Issue
I am trying the following
import pandas as pd
import numpy as np
dfout3 = pd.DataFrame({'Idx': MnthIdx,
'Col1': Val1,
'Col2': Val2,
'Col3': Val3)})
MeanTable1 = pd.pivot_table(dfout3, index=['Idx'], values=['Col1','Col2','Col3'], aggfunc=[np.mean])
But I would like to ignore zeros's while taking the mean for each of values. Is there way through pandas instead of me doing index for zeros and getting rid of them and taking mean of columns?
Solution
While @ysearka's answer points into the right direction, it's not working (anymore?):
This is how the loop works for me:
for col in dfout3.columns:
dfout3.loc[dfout3[col] == 0] = dfout3[col]mean()
Answered By - n.r.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.