I am stuck on calculating the average depends on the variables in python.
I have 8 variables as below.
Case 1.
Time df1 df2 df3 df4 df5 df6 df7 df8
2020-01-01 220 250 235 215 221 221 220 253
In this case I can just calculate average like below
df['dfaverage']=(df['df1']+df['df2']+df['df3']+df['df4']+df['df5']+df['df6']+df['df7']+df['df8'])/8
The output will be 229.4
but if one of the value is zero then how would i ignore that values and calculate? Case 2.
Time df1 df2 df3 df4 df5 df6 df7 df8
2020-01-01 220 250 235 215 221 221 220 0
the output should be 226 for case2 but when I run the code I will get 197.8. How can I ignore 0 when calculating the average?