Closed
Description
I'm trying to get a slice from a multiindex. I find the behavior pretty inconsistent. Here is a simple dataframe:
test = pd.DataFrame({'l': ['A', 'B', 'C', 'C', 'B', 'A'], 'm': [pd.Timestamp('2014-06-11 14:26:27'), pd.Timestamp('2014-06-11 15:26:27'), pd.Timestamp('2014-06-11 16:26:27'), pd.Timestamp('2014-06-12 14:26:27'), pd.Timestamp('2014-06-12 15:26:27'), pd.Timestamp('2014-06-12 16:26:27')]})
With a single index, I can select all the data for a given day as follows:
test_single_index = test.set_index(['m'])
#partial string indexing works
test_single_index.loc['2014-06-11']
But it doesn't work for a multiindex:
test_multi_index = test.set_index(['m', 'l'])
#would expect this to work
test_multi_index.loc['2014-06-11']
#or this
test_multi_index.loc[('2014-06-11', 'A'),:]
#what works
idx = pd.IndexSlice
test_multi_index.loc[idx['2014-06-11':'2014-06-11',:],:]
test_multi_index.loc[idx['2014-06-11','A'],:]
So I can make it work if I specify the slice explicitely, but it would be nice if the behavior for the 1D index carried over to Multiindices.