I am learning pandas and got 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 line I want to add a column that indicates if they user has bought something at all.
This error pops up:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I understand the point of ambiguity in panda's Series (also explained here) but I could not relate it to the problem.
Interestingly this works
df['bought_something'] = df['bought_apples'] > 0
Can anyone help me?