# On using pytables; how do I... A lot of this info is in [the docs for Tables](https://www.pytables.org/usersguide/libref/structured_storage.html#the-table-class). Open the file for reading, and get a reference to a table: ``` >>> with tables.open_file(path, mode='r') as f: ... table = f.root.some_columns.table ``` How many records are in the table? ``` >>> table.nrows ``` Search for a matching row (e.g. row matching the value `12345`) ``` >>> table = f.root.some_table.table >>> table.read_where('some_column==12345') array([(12345, 3928, 364544)] dtype=[('some_column', '>> for row in table.where('some_column==12345') ... print(row['some_column'], row['foo'], row['bar']) ``` Extract a single column for a matching row (similar to above): ``` >>> arr = table.read_where('some_column=12345') >>> bar = arr[0][2] ``` Find a row for a given key (column value), and update a column in that row of the table: ``` >>> arr = table.get_where_list('some_column==12345') >>> key = arr[0] >>> table.cols.bar[key] = 42 ``` Construct a dataframe with all values ``` >>> arr = table.read() >>> df = pd.DataFrame(arr) ``` Add an index to a column of the table: ``` >>> table.cols.some_column.create_index() >>> table.reindex() # to rebuild the index... >>> table.reindex_dirty() # rebuild indexes, if they are dirty. ``` How to add blosc compression? (See the [docs on Filters](https://www.pytables.org/usersguide/libref/helper_classes.html#the-filters-class)) ``` >>> blosc_filter = Filters(complevel=9, complib='blosc') >>> table = fileh.create_table( ... ) >>> table.cols.some_column.create_index(filters=blosc_filter) ```