Skip to content
Advertisement

Filtering multiple items in a multi-index Python Panda dataframe

I have the following table:

JavaScript

Note: Both NSRCODE and PBL_AWI are indices.

How do I search for values in column PBL_AWI? For example I want to keep the values ['Lake', 'River', 'Upland'].

Advertisement

Answer

You can get_level_values in conjunction with Boolean slicing.

JavaScript

The same idea can be expressed in many different ways, such as df[df.index.get_level_values('PBL_AWI').isin(['Lake', 'River', 'Upland'])]

Note that you have 'upland' in your data instead of 'Upland'

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