Reputation: 27
I want to filter the column NAME with just one letter "o".
DataFrame:
NAME | HOBBY |
---|---|
John | football |
Kelly | chess |
df["NAME"].filter(like ="o")
I am looking for an output:
NAME | HOBBY |
---|---|
John | football |
Upvotes: 0
Views: 776
Reputation: 3300
You can use .contains to filter only the rows where name contains a lower case 'o'.
Using the below df:
df = pd.DataFrame({'NAME' : ['John', 'Kelly'],
'HOBBY' : ['football', 'chess']})
Then you can use .loc and .contains to filter on desired rows:
df.loc[df['NAME'].str.contains('o')]
Output:
NAME HOBBY
0 John football
Upvotes: 1