trec nano trec nano -4 years ago 97
Python Question

How to search data in a pivot table in pandas?

I created a pivot table from a dataframe using:

table = pd.pivot_table(df , index=['student','year','subject'] , values=['mark'])

and I got a table like this:

student year subject

'Martin' 2014 Algebra 5
Chemistry 3.5
Programming 8

'Sara' 2013 Algebra 2.2
.... .... .....

How can I get Martin 2014 Algebra's mark?

I tried as a dataframe:


but it doesn't works

Can somebody help me? Thank's!

Answer Source

You have a multi-index data frame, use loc with tuple to access the value:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download