MRocklin
MRocklin

Reputation: 57281

Store pandas DataFrame in PyTables table without storing index

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.

Upvotes: 1

Views: 750

Answers (2)

heroxbd
heroxbd

Reputation: 810

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

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

Upvotes: 0

quasiben
quasiben

Reputation: 1464

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)

Upvotes: 1

Related Questions