I have a dataframe like this
| count | A | B | Total |
|---|---|---|---|
| yes | 4900 | 0 | 0 |
| yes | 1000 | 1000 | 0 |
| sum_yes | 5900 | 1000 | 0 |
| yes | 4000 | 0 | 0 |
| yes | 1000 | 0 | 0 |
| sum_yes | 5000 | 0 | 0 |
I want result like this that is calculate max of column A and B only for rows where 'count' = 'sum_yes' if value of B =0 otherwise calculate minimum
| count | A | B | Total |
|---|---|---|---|
| yes | 4900 | 0 | 0 |
| yes | 1000 | 1000 | 0 |
| sum_yes | 5900 | 1000 | 1000 |
| yes | 4000 | 0 | 0 |
| yes | 1000 | 0 | 0 |
| sum_yes | 5000 | 0 | 5000 |
I have tried this so far:
df['Total'] = [df[['A', 'B']].where(df['count'] == 'sum_yes').max(axis=0) if
'B'==0 else df[['A', 'B']]
.where(df['count'] == 'sum_yes').min(axis=0)]
But I am getting ValueError The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
Any idea how to solve this