IIUC, может сделать:
# Setup (for reproducibility)
import pandas as pd
data = [-8.000,
14.400,
13.150,
3.050,
-8.000,
-8.000,
3.425,
7.350,
-8.000,
-8.000,
0.000]
df = pd.DataFrame(data, columns=["ProfitLoss"])
# Calculate the respective means (vectorized)
avgGain = df[df['ProfitLoss'] > 0].mean().values[0]
avgLoss = df[df['ProfitLoss'] < 0].mean().values[0]
# Print outputs to console
print("avgGain:", avgGain)
print("avgLoss:", avgLoss)
выходы:
Matthews-MacBook-Pro:stackoverflow matt$ python test.py
avgGain: 8.275
avgLoss: -8.0
по желанию