@@ -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
@@ -3934,29 +3936,6 @@ returned, this is equivalent to passing a
3934
3936
3935
3937
store.select(' df' , " columns=['A', 'B']" )
3936
3938
3937
- Using level name when querying MultiIndex DataFrame.
3938
-
3939
- .. ipython :: python
3940
-
3941
- store.select(' df_mi' , " foo=baz and bar=two" )
3942
-
3943
- Using ``level_0 `` and ``level_1 `` for MultiIndex without name.
3944
-
3945
- .. ipython :: python
3946
-
3947
- index = pd.MultiIndex(
3948
- levels = [[" foo" , " bar" , " baz" , " qux" ], [" one" , " two" , " three" ]],
3949
- codes = [[0 , 0 , 0 , 1 , 1 , 2 , 2 , 3 , 3 , 3 ], [0 , 1 , 2 , 0 , 1 , 1 , 2 , 0 , 1 , 2 ]],
3950
- )
3951
- df_mi_2 = pd.DataFrame(np.random.randn(10 , 3 ),
3952
- index = index, columns = [" A" , " B" , " C" ])
3953
- df_mi_2
3954
-
3955
- store.append(" df_mi_2" , df_mi_2)
3956
-
3957
- # the levels are automatically included as data columns
3958
- store.select(" df_mi_2" , " level_0=foo and level_1=two" )
3959
-
3960
3939
``start `` and ``stop `` parameters can be specified to limit the total search
3961
3940
space. These are in terms of the total number of rows in a table.
3962
3941
@@ -3971,7 +3950,7 @@ space. These are in terms of the total number of rows in a table.
3971
3950
3972
3951
.. _io.hdf5-timedelta :
3973
3952
3974
- Using timedelta64[ns]
3953
+ Query timedelta64[ns]
3975
3954
+++++++++++++++++++++
3976
3955
3977
3956
You can store and query using the ``timedelta64[ns] `` type. Terms can be
@@ -3990,6 +3969,35 @@ specified in the format: ``<float>(<unit>)``, where float may be signed (and fra
3990
3969
store.append(' dftd' , dftd, data_columns = True )
3991
3970
store.select(' dftd' , " C<'-3.5D'" )
3992
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
+
3993
4001
Indexing
3994
4002
++++++++
3995
4003
0 commit comments