Store pandas DataFrame in PyTables table without storing index

妖精的绣舞 提交于 2019-12-13 18:41:40

问题


In many DataFrame.to_foo functions I can specify that I don't want to write the index

>>> help(df.to_csv)

Write DataFrame to a comma-separated values (csv) file

Parameters
----------
...
index : boolean, default True
    Write row names (index)
...

Does similar functionality exist for DataFrame.to_hdf? I would like to not store the index in the PyTables table.


回答1:


You could call out to h5py and interact with HDF5 directly.

data = df.values
with h5py.File('data.h5','w') as f:
    f.create_dataset('my_table', data=data)



回答2:


Suppressing index is not out of the box with Pandas. The issue is tracked at

https://github.com/pydata/pandas/issues/8319



来源:https://stackoverflow.com/questions/25516923/store-pandas-dataframe-in-pytables-table-without-storing-index

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