Skip to content
Advertisement

index string has no method of isin()

I have a dataframe with index is string name like ‘apple’ etc.

Now I have a list

name_list=[‘apple’,’orange’,’tomato’]

I’d like to filter dataframe rows by selecting rows with index is in the above list

JavaScript

then I got an error of

JavaScript

Advertisement

Answer

Use df.index.isin, not df.index.str.isin:

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