I've got a pandas dataframe with the column 'Friends'. All elements in the column friends are list object. Example of a row in the column 'friends':
['erik', 'jason', 'eduard']
I want to return a dataframe in which I check whether eduard is the list. This is my example code:
df[df.friends.isin(['eduard'])
Help a cat out please
You need apply
in this case, use the normal in
operator to check if list contains eduard
:
df[df.friends.apply(lambda x: 'eduard' in x)]
Example:
df = pd.DataFrame({"friends": [['erik', 'jason', 'eduard'], ['erik', 'jason']]})
df[df.friends.apply(lambda x: 'eduard' in x)]
# friends
#0 [erik, jason, eduard]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With