Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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’]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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


df=df.loc[df.index.str.isin(name_list)]

then I got an error of

AttributeError: 'StringMethods' object has no attribute 'isin'

>Solution :

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

df = df.loc[df.index.isin(name_list)]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading