pandas.HDFStore.create_table_index#
- HDFStore.create_table_index(key, columns=None, optlevel=None, kind=None)[source]#
Create a pytables index on the table.
Indexes are automatically created on indexable axes and
data_columnsduringappend/putwhenindex=True(the default). This method lets you add or rebuild indexes after the fact, which is highly encouraged because it greatly speeds upselectcalls that filter on the indexed dimension.- Parameters:
- keystr
Object stored in the file to index.
- columnsNone, bool, or listlike[str]
Indicate which columns to create an index on.
False : Do not create any indexes.
True : Create indexes on all columns.
None : Create indexes on all columns.
listlike : Create indexes on the given columns.
- optlevelint or None, default None
Optimization level, if None, pytables defaults to 6.
- kindstr or None, default None
Kind of index, if None, pytables defaults to “medium”.
- Raises:
- TypeError
If the node is not a table.
See also
HDFStore.appendAppend data to an existing table; columns are indexed automatically by default.
HDFStore.selectFilter on indexed columns for fast retrieval.
Examples
>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=["A", "B"]) >>> store = pd.HDFStore("store.h5", "w") >>> store.append("data", df, format="table", index=False) >>> store.create_table_index("data", columns=["A"]) >>> store.close()