on-internet
← Community

Mean calculation in pandas, excluding zeros

Stack Overflow ·

Is there a direct way to calculate the mean of a dataframe column in pandas, but not taking into account data that has zero as a value? Like a parameter inside the .mean() function? I was currently doing it like this: x = df[df[A]!=0] x.mean()

Comments

Sign in or sign up to comment and upvote.

No comments yet.