Q:

selecting row with multi index

I have following DB, how i can select a row by retailer_name, visit_number, visit_date ?
category_name                                                     Blades & Razors & Foam  Diaper
    retailer_name store_number visit_date                                         
    ABest         1177         2016-03-01 06:10:49                      86     191
                               2016-03-24 08:59:33                     129     222
                               2016-03-29 04:34:36                     114     323
                               2016-04-12 10:56:26                     225     235
                  1182         2016-03-02 08:54:00                     161     217

For example I want to get  row for 'ABest', 1182, 2016-03-02 08:54:00
Thanks

A:

I think you can use loc with slicers - docs:
import pandas as pd

df = pd.DataFrame({'Blades & Razors & Foam': {('ABest', 1177, pd.Timestamp('2016-03-01 06:10:49')): 86, ('ABest', 1177, pd.Timestamp('2016-03-29 04:34:36')): 114, ('ABest', 1177, pd.Timestamp('2016-03-24 08:59:33')): 129, ('ABest', 1177, pd.Timestamp('2016-04-12 10:56:26')): 225, ('ABest', 1182, pd.Timestamp('2016-03-02 08:54:00')): 161}, 'Diaper': {('ABest', 1177, pd.Timestamp('2016-03-01 06:10:49')): 191, ('ABest', 1177, pd.Timestamp('2016-03-29 04:34:36')): 323, ('ABest', 1177, pd.Timestamp('2016-03-24 08:59:33')): 222, ('ABest', 1177, pd.Timestamp('2016-04-12 10:56:26')): 235, ('ABest', 1182, pd.Timestamp('2016-03-02 08:54:00')): 217}})
df.columns.names=[u'category_name'] 
df.index.names=[u'retailer_name', u'store_number', u'visit_date'] 
print (df)
category_name                                   Blades & Razors & Foam  Diaper
retailer_name store_number visit_date                                         
ABest         1177         2016-03-01 06:10:49                      86     191
                           2016-03-24 08:59:33                     129     222
                           2016-03-29 04:34:36                     114     323
                           2016-04-12 10:56:26                     225     235
              1182         2016-03-02 08:54:00                     161     217

idx = pd.IndexSlice
print (df.loc[idx['ABest',1182,'2016-03-02 08:54:00'],:])
category_name                                   Blades & Razors & Foam  Diaper
retailer_name store_number visit_date                                         
ABest         1182         2016-03-02 08:54:00                     161     217

EDIT:
If you need change level visit_date to_datetime, you can use:
import pandas as pd

df = pd.DataFrame({'Blades & Razors & Foam': {('ABest', 1182, '2016-03-02 08:54:00'): 161, ('ABest', 1177, '2016-04-12 10:56:26'): 225, ('ABest', 1177, '2016-03-01 06:10:49'): 86, ('ABest', 1177, '2016-03-24 08:59:33'): 129, ('ABest', 1177, '2016-03-29 04:34:36'): 114}, 'Diaper': {('ABest', 1182, '2016-03-02 08:54:00'): 217, ('ABest', 1177, '2016-04-12 10:56:26'): 235, ('ABest', 1177, '2016-03-01 06:10:49'): 191, ('ABest', 1177, '2016-03-24 08:59:33'): 222, ('ABest', 1177, '2016-03-29 04:34:36'): 323}})
df.index.names=[u'retailer_name', u'store_number', u'visit_date'] 
print (df)
                                                Blades & Razors & Foam  Diaper
retailer_name store_number visit_date                                         
ABest         1177         2016-03-01 06:10:49                      86     191
                           2016-03-24 08:59:33                     129     222
                           2016-03-29 04:34:36                     114     323
                           2016-04-12 10:56:26                     225     235
              1182         2016-03-02 08:54:00                     161     217

df.reset_index(inplace=True)
df['visit_date'] = pd.to_datetime(df['visit_date'])
df.set_index(['retailer_name','store_number','visit_date'], inplace=True)

idx = pd.IndexSlice
print (df.loc[idx['ABest',1182,'2016-03-02 08:54:00'],:])
                                                Blades & Razors & Foam  Diaper
retailer_name store_number visit_date                                         
ABest         1182         2016-03-02 08:54:00                     161     217

