我想逐步讀寫數據到hdf5文件,因爲我無法將數據放入內存。Pandas HDFStore用於外核對可變大小的集合的順序讀取/寫入
要讀取/寫入的數據是整數集。我只需要按順序讀取/寫入集合。不需要隨機訪問。就像我讀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}
'指數= FALSE' http://stackoverflow.com/questions/25714549/indexing-and-data-columns-in-pandas-pytables –
,你可以簡單地做這個:'y = x.select('dframe',start = 0,stop = 1 + 1)' – MaxU
@MaxU。但是這意味着我知道在我從文件中讀取之前,該集合有兩個元素,事實並非如此。當我讀取文件時,我不知道集合的大小。 –