我想增量地读取和写入数据到hdf5文件,因为我无法将数据放入内存。
要读/写的数据是整数集。我只需要按顺序读/写集合。不需要随机访问。就像我读set1,然后是set2,然后是set3,等等。
问题是我不能通过索引检索集合。
import pandas as pd
x = pd.HDFStore('test.hf', 'w', append=True)
a = pd.Series([1])
x.append('dframe', a, index=True)
b = pd.Series([10,2])
x.append('dframe', b, index=True)
x.close()
x = pd.HDFStore('test.hf', 'r')
print(x['dframe'])
y=x.select('dframe',start=0,stop=1)
print("selected:", y)
x.close()
输出:
0 1
0 10
1 2
dtype: int64
selected: 0 1
dtype: int64
它不会选择我的第0个集合,即{1,10}
发布于 2017-03-25 14:07:06
这种方式是可行的。但我真的不知道这有多快。
这是否会扫描整个文件以查找具有索引的行?
那将是相当浪费时间的。
import pandas as pd
x = pd.HDFStore('test.hf', 'w', append=True, format="table", complevel=9)
a = pd.Series([1])
x.append('dframe', a, index=True)
b = pd.Series([10,2])
x.append('dframe', b, index=True)
x.close()
x = pd.HDFStore('test.hf', 'r')
print(x['dframe'])
y=x.select('dframe','index == 0')
print('selected:')
for i in y:
print(i)
x.close()
输出:
0 1
0 10
1 2
dtype: int64
selected:
1
10
https://stackoverflow.com/questions/43017015
复制