Reading and writing pandas DataFrames to HDF5 stores

The HDFStore class is the pandas abstraction responsible for dealing with HDF5 data. Using random data and temporary files, we will demonstrate this functionality. These are the steps to do so:

Give the HDFStore constructor the path to a temporary file and create a store:

store = pd.io.pytables.HDFStore(tmpf.name)
print store

The preceding code snippet will print the file path to the store and its contents, which is empty at the moment:

<class 'pandas.io.pytables.HDFStore'>
File path: /var/folders/k_/xx_xz6xj0hx627654s3vld440000gn/T/tmpfmwPPB
Empty

HDFStore has a dict-like interface, meaning that we can store values, for instance, a pandas DataFrame with a corresponding lookup key. Store a DataFrame ...

Get Python Data Analysis now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.