Reputation: 333
I have a dataframe as below:
I would like to take a result with filter city is San Francisco and score > 90, i wrote the code like below:
df[df['city'].str.contains('San') and df['score'] > 90]
df
however, it show the error is "ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()." . Can someone assist me on this ? Thank you
however, it v
Upvotes: 1
Views: 435
Reputation: 26686
Use regex, starts with in the str.contains
df[(df['city'].str.contains('^[San]')) & (df['score'] > 90)]
Upvotes: 3