I am learning pandas and stuck with this problem here.
I created a dataframe that tracks all users and the number of times they did something.
To better understand the problem, I created this example:
import pandas as pd data = [ {'username': 'me', 'bought_apples': 2, 'bought_pears': 0}, {'username': 'you', 'bought_apples': 1, 'bought_pears': 1} ] df = pd.DataFrame(data) df['bought_something'] = df['bought_apples'] > 0 or df['bought_pears'] > 0
In the last row, I want to add a column that indicates that they generally bought something.
This error appears:
ValueError: The truth value of the series is ambiguous. Use the a.empty, a.bool (), a.item (), a.any (), or a.all () commands.
I understand the meaning of the ambiguity in the panda Series ( also explained here ), but I could not relate this to the problem.
Interesting that it works
df['bought_something'] = df['bought_apples'] > 0
Can anybody help me?
linqu source share