I am trying to calculate aggregate using a lambda function with if... else.
My dataframe looks like this
States Sales
0 Delhi 0.0
1 Kerala 2.5
2 Punjab 5.0
3 Haryana 7.5
4 Delhi 10.0
5 Kerala 12.5
6 Punjab 15.0
7 Haryana 17.5
Expected summary table should like this
States Sales
Delhi 10.0
Haryana 25.0
Kerala 15.0
Punjab 20.0
I tried using the following code
df.groupby('States').agg({
'Sales':lambda x: np.sum(x) if (x>7) else 0
})
I get ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
What am I doing wrong?