I have a dataframe as below.
df
Out[209]:
a b
User1 2019-07-01 [The Milky Way]
2019-07-02 NaN
2019-07-03 [Taken]
2019-07-04 NaN
2019-07-05 [The Lobster]
2019-07-06 [Bloody Sunday]
2019-07-07 [Lost in Translation]
2019-07-08 NaN
2019-07-09 NaN
2019-07-10 [Face Off]
2019-07-11 [The Thief of Bagdad]
2019-07-12 NaN
2019-07-13 [Charade]
2019-07-14 [Scarface]
2019-07-15 [Anchorman 2: The Legend Continues]
I am trying to access the multiindex, when I access one level, i get the desired output.
df.loc['User1']
Out[211]:
b
2019-07-01 [The Milky Way]
2019-07-02 NaN
2019-07-03 [Taken]
2019-07-04 NaN
2019-07-05 [The Lobster]
But when i am trying the multilevel index accessing, it gives me the error as below.
df.loc['User1','2019-07-13']
IndexingError: Too many indexers
Index looks like this :
MultiIndex(levels=[['User1', 'User2', 'User3', 'User4', 'User5', 'User6', 'User7', 'User8', 'User9', 'User10'], [2019-07-01, 2019-07-02, 2019-07-03, 2019-07-04, 2019-07-05, 2019-07-06, 2019-07-07, 2019-07-08, 2019-07-09, 2019-07-10, 2019-07-11, 2019-07-12, 2019-07-13, 2019-07-14, 2019-07-15, 2019-07-16, 2019-07-17, 2019-07-18, 2019-07-19, 2019-07-20, 2019-07-21, 2019-07-22, 2019-07-23, 2019-07-24, 2019-07-25, 2019-07-26, 2019-07-27, 2019-07-28, 2019-07-29, 2019-07-30, 2019-07-31, 2019-08-01, 2019-08-02, 2019-08-03, 2019-08-04, 2019-08-05, 2019-08-06, 2019-08-07, 2019-08-08, 2019-08-09, 2019-08-10, 2019-08-11, 2019-08-12, 2019-08-13, 2019-08-14, 2019-08-15, 2019-08-16, 2019-08-17, 2019-08-18, 2019-08-19, 2019-08-20]]
How do I get past the error and access the multiindex.
I have found a proposed solution already in another question, but i get the below error.
upon trying the axis = 0 argument, i get the error as KeyError: ('User1', '2019-07-13')