Reputation: 1260
I am trying to delete the rows that do not contain "HW" or "CA" in column Vndr. This is my code:
data.drop(data[data.Vndr != 'HW' or 'CA'].index)
I am getting this error "ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."
Upvotes: 1
Views: 83
Reputation: 65
Instead of deleting such rows, you can subset the rows which do not have such keywords.
You can work like this:
data = data[(data['Vndr'] != 'CA') | (data['Vndr'] != 'HW')]
Upvotes: 0
Reputation: 59274
Can use
data[data.Vndr.str.contains('HW|CA'])
General approach
s="|".join(['HW', 'CA'])
data[data.Vndr.str.contains(s)
Upvotes: 1
Reputation: 8266
it needs to actually be
... or data.Vndr != ‘CA’
Otherwise it doesn’t make sense
Upvotes: 0