Boosted_d16
Boosted_d16

Reputation: 14082

pandas python: access row by case insensitive label

I have a df and I would like to access a row by label, but I would like the casing of the label to be ignored.

my df looks like this:

Name  exp1
Name      
Base  2074
Raw   2014

My failed attempt:

df.index.str.contains('base')

Note, I would like to avoid using the str.lower approach to solving this.

Upvotes: 0

Views: 2783

Answers (1)

chrisb
chrisb

Reputation: 52256

This should work - need to convert the index to a Series first.

df[pd.Series(df.index).str.contains('base', case=False)]

Upvotes: 3

Related Questions