Getting average of rows in dataframe greater than or equal to zero

Viewed 4468

I would like to get the average value of a row in a dataframe where I only use values greater than or equal to zero.

For example: if my dataframe looked like:

df = pd.DataFrame([[3,4,5], [4,5,6],[4,-10,6]])
    3   4   5
    4   5   6
    4   -10 6

currently if I get the average of the row I write :

df['mean'] = df.mean(axis = 1)

and get:

3   4   5   4
4   5   6   5
4   -10 6   0

I would like to get a dataframe that only used values greater than zero to computer the average. I would like a dataframe that looked like:

3   4   5   4
4   5   6   5
4   -10 6   5

In the above example -10 is excluded in the average. Is there a command that excludes the -10?

2 Answers
Related