0

I am trying to combine the condition of a column in indexing data frame but it's giving me an error

The truth value of a Series is ambiguous.

Giving an example, there is a data frame df:

A B
0 a
1 b
2 c
3 b
4 b

I count the rows with B is 'a' or 'b' by following:

len(df[df['B'] in ['a', 'b'])

and output is an error:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

while I expect to be 4. This is mean to be an example, what if I want to do with more values in the list other than just 'a' and 'b'

0 Answers0