What I'm trying to do is a multiple conditional average. It means that I have a list of x variables (of the same length) and I'd like to compute the average of one variable conditioned to the value/range of the others.
The file is:

The code I tried is:
wb=pd.ExcelFile('file.xlsx')
wb.sheet_names
df=wb.parse('Sheet1')
df[:]
Var1=df['Col1_Name']
Var2=df['Col2_Name']
Var3=df['Col3_Name']
Var4=df['Col4_Name']
Var5=df['Col5_Name']
Var6=df['Col6_Name']
if (Var1 == 0).any() and (Var2 == 0).any() and (Var3 < 0.8).any() and (Var6 == 0).any():
print sum(Var4)/len(Var4)
It seems to be ok, but, if I change the conditions, the result is always the same. Moreover I tried to calculate the same on Excel as double check and the result is indeed different.. Could you help me? Thank you :)
What you have written seems all sorts of wrong. I believe what you want is:
(Var1 == 0).all() and (Var2 == 0) and (Var3 >= 0).all() and (Var3 < 1).all() and (Var6 == 0).all()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With