Skip to content
Advertisement

Find values in indexed columns of pandas

Let’s say I have a dataframe like following

JavaScript

Now, I want to index all the columns.. indexed_df = df.set_index(['col1', 'col2', 'col3'])

How do I search for a particular value in this indexed df

Like if i want to search for baz in df I will do

JavaScript

How do I do the same thing with indexed_df

Advertisement

Answer

There are several ways:

Option 1: query

JavaScript

Option 2: xs

JavaScript

Option 3: get_level_values:

JavaScript

Let’s assume that there is some data

JavaScript

Any of the above would give:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement