Consider some sample pandas dataset:
df = pd.DataFrame([[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[0, 0, 0]],
columns=['A', 'B', 'C'])
Now, I want to aggregate each column (say calculating the mean) where I want to exclude the zeros. I can see there is agg
function that can be called but I could not figure out how to exclude the zeros when calculating the mean.
I know when mapping the columns, I need to somehow filter out the zeros but I cannot figure out how to include that in the call to the df.agg()
function.
question from:
https://stackoverflow.com/questions/65835868/pandas-exclude-zeros-when-aggregating 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…