问题
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