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

How to search for name in dataframe

For example I want to find all the people that has "Abbott" in their name

0                        Abbing, Mr. Anthony
1                Abbott, Mr. Rossmore Edward
2           Abbott, Mrs. Stanton (Rosa Hunt)
3                        Abelson, Mr. Samuel
4      Abelson, Mrs. Samuel (Hannah Wizosky)
                       ...                  
886                  de Mulder, Mr. Theodore
887                de Pelsmaeker, Mr. Alfons
888                del Carlo, Mr. Sebastiano
889          van Billiard, Mr. Austin Blyler
890              van Melkebeke, Mr. Philemon
Name: Name, Length: 891, dtype: object

df.loc[name in df["Name"]]
I tried this and it didn’t work

'False: boolean label can not be used without a boolean index'

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

>Solution :

You can use str.contains with the column you are interested in searching

>>> import pandas as pd
>>> df = pd.DataFrame(data={'Name': ['Smith', 'Jones', 'Smithson']})
>>> df
       Name
0     Smith
1     Jones
2  Smithson
>>> df[df['Name'].str.contains('Smith')]
       Name
0     Smith
2  Smithson
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