JOHN
JOHN

Reputation: 1511

Filter rows of multiindex columns in Pandas

I have the following dataframe. When I tried to select rows with data[('PIC_next','last')] == 'Business', all rows return False.

Is it the right way to filter multiindex column?

I have referred to this question. It seems that I am correct.

I created this dataframe by using groupby.

enter image description here

Upvotes: 1

Views: 62

Answers (1)

jezrael
jezrael

Reputation: 862511

I think you are correct.

Reason why not match should be in data, maybe traling whitespaces.

You can check it:

print (data[('PIC_next','last')].tolist())

And then remove it:

data[('PIC_next','last')].str.strip() == 'Business'

Upvotes: 1

Related Questions