I'm probably missing something, but I was not able to find a solution for this. Is there a way in python to add values to a new column which satisfy a certain condition. In Excel I would apply the following formula in the new column and paste it below
=SUMIF(A1:C1, ">0")
| val1 | val2 | val3 | output |
|---|---|---|---|
| 0.5 | 0.7 | -0.9 | 1.2 |
| 0.3 | -0.7 | 0.3 | |
| -0.5 | -0.7 | -0.9 | 0 |
Also in my extracts, there are a few blank values. Can you please help me understand what code should be written for this?
df['total'] = df[['A','B']].sum(axis=1).where(df['A'] > 0, 0)
I came across the above code, but it checks only one condition. What I need is a sum of all of those columns which match the given condition.
Thanks!