Having difficulty getting multiple columns in HDF5 Table Data

落花浮王杯 提交于 2020-01-16 19:38:11

问题


I am new to hdf5 and was trying to store a DataFrame row into the hdf5 format. I was to append a row at different locations within the file; however, every time I append it shows up at an array in a single column rather than a single value in multiple columns.

I have tried both h5py and pandas and it seems like pandas is the better option for appending. Additionally, I have really been trying a lot of different methods. Truly, any help would be greatly appreciated.

Here is me sending an array multiple times into the hdf5 file.


import pandas as pd
import numpy as np
data = np.zeros((1,48), dtype = float)

columnName = ['Hello'+str(y) for (x,y), item in np.ndenumerate(data)]
df = pd.DataFrame(data = data, columns =columnName)

file = pd.HDFStore('file.hdf5', mode = 'a', complevel = 9, comlib = 'blosc')
for x in range(0,11):
    file.put('/data', df, column_data = columnName , append = True, format = 'table')

回答1:


In [243]: store = pd.HDFStore('test.h5')                                               

This seems to work fine:

In [247]: store.put('foo',df,append=True,format='table')                               
In [248]: store.put('foo',df,append=True,format='table')                               
In [249]: store.put('foo',df,append=True,format='table')                               
In [250]: store['foo']                                                                 
Out[250]: 
   Hello0  Hello1  Hello2  Hello3  Hello4  ...  Hello43  Hello44  Hello45  Hello46  Hello47
0     0.0     0.0     0.0     0.0     0.0  ...      0.0      0.0      0.0      0.0      0.0
0     0.0     0.0     0.0     0.0     0.0  ...      0.0      0.0      0.0      0.0      0.0
0     0.0     0.0     0.0     0.0     0.0  ...      0.0      0.0      0.0      0.0      0.0

[3 rows x 48 columns]


来源:https://stackoverflow.com/questions/58029991/having-difficulty-getting-multiple-columns-in-hdf5-table-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!