Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Hdf5文件中未显示的列_Python_Pandas_Hdf5_Vaex - Fatal编程技术网

Python Hdf5文件中未显示的列

Python Hdf5文件中未显示的列,python,pandas,hdf5,vaex,Python,Pandas,Hdf5,Vaex,我有一个大数据集13亿个数据,我想用Vaex可视化。由于csv中的数据集非常大,大约130gb,在520个单独的文件中,我将它们合并到一个hdf5文件中,并为每个csv文件添加pandas dataframe.to_hdf function format:table。如果我使用pandas.read_hdf函数加载一段数据,就不会有问题 x y z 0 -8274.591528 36.053843 24.766887 1 -8273.229203 34.8

我有一个大数据集13亿个数据,我想用Vaex可视化。由于csv中的数据集非常大,大约130gb,在520个单独的文件中,我将它们合并到一个hdf5文件中,并为每个csv文件添加pandas dataframe.to_hdf function format:table。如果我使用pandas.read_hdf函数加载一段数据,就不会有问题

    x   y   z
0   -8274.591528    36.053843   24.766887
1   -8273.229203    34.853409   21.883050
2   -8289.577896    15.326737   26.041516
3   -8279.589741    27.798428   26.222326
4   -8272.836821    37.035071   24.795912
...     ...     ...     ...
995     -8258.567634    3.581020    23.955874
996     -8270.526953    4.373765    24.381293
997     -8287.429578    1.674278    25.838418
998     -8250.624879    4.884777    21.815401
999     -8287.115655    1.100695    25.931318

1000 rows × 3 columns
这就是它看起来的样子,我可以访问我想要的任何列,形状是1000,3。但是,当我尝试使用vaex.open函数加载hdf5文件时:

 #  table
0   '(0, [-8274.59152784, 36.05384262, 24.7668...
1   '(1, [-8273.22920299, 34.85340869, 21.8830...
2   '(2, [-8289.5778959 , 15.32673748, 26.0415...
3   '(3, [-8279.58974054, 27.79842822, 26.2223...
4   '(4, [-8272.83682085, 37.0350707 , 24.7959...
...     ...
1,322,286,736   '(2792371, [-6781.56835851, 2229.30828904, -6...
1,322,286,737   '(2792372, [-6781.71119626, 2228.78749838, -6...
1,322,286,738   '(2792373, [-6779.3251589 , 2227.46826613, -6...
1,322,286,739   '(2792374, [-6777.26078082, 2229.49535808, -6...
1,322,286,740   '(2792375, [-6782.81758335, 2228.87820639, -6...
这就是我得到的。形状是1322286741,1,只有一列是“table”。当我尝试将vaex导入的hdf称为Galado[0]时:

[(0, [-8274.59152784,    36.05384262,    24.76688728])]

在导入的数据中,这些是第一行的x、y、z列。当我试图检查另一个问题中的数据时,它也给出了一个错误,表示没有找到数据。所以我认为问题在于熊猫一行一行地添加hdf5文件,而这在其他程序中不起作用。有没有办法解决这个问题

hdf5与JSON和xml一样灵活,您可以以任何方式存储数据。Vaex有自己的数据存储方式,您可以使用h5ls utils结构检查数据,它非常简单,与Pandas/PyTables的存储方式不一致

Vaex将每个列存储为单个连续数组,如果不使用所有列,这是最佳选择,并且可以轻松地将内存映射到真正的numpy数组。PyTables将至少相同类型的每一行存储在彼此相邻的位置。这意味着,如果要计算x列的平均值,则可以有效地检查所有数据

由于PyTables hdf5的读取速度可能已经比CSV快得多,因此我建议您执行以下未经测试的操作,但它应该能够理解这一点:

import vaex
import pandas as pd
import glob
# make sure dir vaex exists
for filename in glob.glob("pandas/*.hdf5"):  # assuming your files live there
    pdf = pd.read_hdf(filename)
    df = vaex.from_pandas(pdf)  # now df is a vaex dataframe
    df.export(filename.replace("pandas", "vaex"), progress=True)) # same in vaex' format

df = vaex.open("vaex/*.hdf5")  # it will be concatenated
# don't access df.x.values since it's not a 'real' numpy array, but 
# a lazily concatenated column, so it would need to memory copy.
# If you need that, you can optionally do (and for extra performance)
# df.export("big.hdf5", progress=True)
# df_single = vaex.open("big.hdf5")
# df_single.x.values  # this should reference the original data on disk (no mem copy)

hdf5与JSON和xml一样灵活,可以以任何方式存储数据。Vaex有自己的数据存储方式,您可以使用h5ls utils结构检查数据,它非常简单,与Pandas/PyTables的存储方式不一致

Vaex将每个列存储为单个连续数组,如果不使用所有列,这是最佳选择,并且可以轻松地将内存映射到真正的numpy数组。PyTables将至少相同类型的每一行存储在彼此相邻的位置。这意味着,如果要计算x列的平均值,则可以有效地检查所有数据

由于PyTables hdf5的读取速度可能已经比CSV快得多,因此我建议您执行以下未经测试的操作,但它应该能够理解这一点:

import vaex
import pandas as pd
import glob
# make sure dir vaex exists
for filename in glob.glob("pandas/*.hdf5"):  # assuming your files live there
    pdf = pd.read_hdf(filename)
    df = vaex.from_pandas(pdf)  # now df is a vaex dataframe
    df.export(filename.replace("pandas", "vaex"), progress=True)) # same in vaex' format

df = vaex.open("vaex/*.hdf5")  # it will be concatenated
# don't access df.x.values since it's not a 'real' numpy array, but 
# a lazily concatenated column, so it would need to memory copy.
# If you need that, you can optionally do (and for extra performance)
# df.export("big.hdf5", progress=True)
# df_single = vaex.open("big.hdf5")
# df_single.x.values  # this should reference the original data on disk (no mem copy)