0

I have a dataframe that's several thousand lines long, structured like below. I want to identify which rows have the string "John" and then I want to return those rows so that I can see the values (not just a row id and "True"/"False).

How can I accomplish this? I've been using the str.contains('John') but that just gives me one column with a bunch of boolean responses which is meaningless to me in that form.

FName
JohnDoe
JaneDoe
SallieMae

Tony
  • 221
  • 1
  • 4
  • 11

1 Answers1

0

Let's try to filter data frame to just those names:

df[df.FName.str.contains('John')]

Or this to added a new column to existing dataframe:

df['Johnames'] = df.FName[df.FName.str.contains('John')]

Output:

       FName Johnames
0    JohnDoe  JohnDoe
1    JaneDoe      NaN
2  SallieMae      NaN
Scott Boston
  • 147,308
  • 15
  • 139
  • 187