In a pandas dataframe, how do I populate a column value conditionally with values in another column that is part of a list?
This is very similar to this SO question , but when I apply:
df['type'] = np.where(df['food'] in ['apple', 'banana', 'kiwi'], 'fruit', 'oth. food')
There was an error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I believe that the operator has innot been redefined to work with vectors.
source
share