I want to calculate the conditional mean of a column: If the values of the row elements are >0 then calculate mean of all such elements and if <0 then calculate the mean of these and store in avgGain and avgLoss.
Input:
ProfitLoss
-8.000
14.400
13.150
3.050
-8.000
-8.000
3.425
7.350
-8.000
-8.000
0.000
Output:
avgGain avgLoss
8.275 -8.000
All these calculations should happen using either pandas apply or aggregate functions in a single statement.
Thanks