@@ -3811,6 +3811,8 @@ storing/selecting from homogeneous index ``DataFrames``.
3811
3811
# the levels are automatically included as data columns
3812
3812
store.select(' df_mi' , ' foo=bar' )
3813
3813
3814
+ .. note ::
3815
+ The ``index `` keyword is reserved and cannot be use as a level name.
3814
3816
3815
3817
.. _io.hdf5-query :
3816
3818
@@ -3829,6 +3831,7 @@ A query is specified using the ``Term`` class under the hood, as a boolean expre
3829
3831
3830
3832
* ``index `` and ``columns `` are supported indexers of ``DataFrames ``.
3831
3833
* if ``data_columns `` are specified, these can be used as additional indexers.
3834
+ * level name in a MultiIndex, with default name ``level_0 ``, ``level_1 ``, … if not provided.
3832
3835
3833
3836
Valid comparison operators are:
3834
3837
@@ -3947,7 +3950,7 @@ space. These are in terms of the total number of rows in a table.
3947
3950
3948
3951
.. _io.hdf5-timedelta :
3949
3952
3950
- Using timedelta64[ns]
3953
+ Query timedelta64[ns]
3951
3954
+++++++++++++++++++++
3952
3955
3953
3956
You can store and query using the ``timedelta64[ns] `` type. Terms can be
@@ -3966,6 +3969,35 @@ specified in the format: ``<float>(<unit>)``, where float may be signed (and fra
3966
3969
store.append(' dftd' , dftd, data_columns = True )
3967
3970
store.select(' dftd' , " C<'-3.5D'" )
3968
3971
3972
+ Query MultiIndex
3973
+ ++++++++++++++++
3974
+
3975
+ Selecting from a ``MultiIndex `` can be achieved by using the name of the level.
3976
+
3977
+ .. ipython :: python
3978
+
3979
+ df_mi.index.names
3980
+ store.select(' df_mi' , " foo=baz and bar=two" )
3981
+
3982
+ If the ``MultiIndex `` levels names are ``None ``, the levels are automatically made available via
3983
+ the ``level_n `` keyword with ``n `` the level of the ``MultiIndex `` you want to select from.
3984
+
3985
+ .. ipython :: python
3986
+
3987
+ index = pd.MultiIndex(
3988
+ levels = [[" foo" , " bar" , " baz" , " qux" ], [" one" , " two" , " three" ]],
3989
+ codes = [[0 , 0 , 0 , 1 , 1 , 2 , 2 , 3 , 3 , 3 ], [0 , 1 , 2 , 0 , 1 , 1 , 2 , 0 , 1 , 2 ]],
3990
+ )
3991
+ df_mi_2 = pd.DataFrame(np.random.randn(10 , 3 ),
3992
+ index = index, columns = [" A" , " B" , " C" ])
3993
+ df_mi_2
3994
+
3995
+ store.append(" df_mi_2" , df_mi_2)
3996
+
3997
+ # the levels are automatically included as data columns with keyword level_n
3998
+ store.select(" df_mi_2" , " level_0=foo and level_1=two" )
3999
+
4000
+
3969
4001
Indexing
3970
4002
++++++++
3971
4003
0 commit comments