For example I want to find all the people that has “Abbott” in their name
JavaScript
x
13
13
1
0 Abbing, Mr. Anthony
2
1 Abbott, Mr. Rossmore Edward
3
2 Abbott, Mrs. Stanton (Rosa Hunt)
4
3 Abelson, Mr. Samuel
5
4 Abelson, Mrs. Samuel (Hannah Wizosky)
6
7
886 de Mulder, Mr. Theodore
8
887 de Pelsmaeker, Mr. Alfons
9
888 del Carlo, Mr. Sebastiano
10
889 van Billiard, Mr. Austin Blyler
11
890 van Melkebeke, Mr. Philemon
12
Name: Name, Length: 891, dtype: object
13
df.loc[name in df[“Name”]] I tried this and it didn’t work
JavaScript
1
2
1
'False: boolean label can not be used without a boolean index'
2
Advertisement
Answer
You can use str.contains
with the column you are interested in searching
JavaScript
1
12
12
1
>>> import pandas as pd
2
>>> df = pd.DataFrame(data={'Name': ['Smith', 'Jones', 'Smithson']})
3
>>> df
4
Name
5
0 Smith
6
1 Jones
7
2 Smithson
8
>>> df[df['Name'].str.contains('Smith')]
9
Name
10
0 Smith
11
2 Smithson
12