SpanishBoy
SpanishBoy

Reputation: 2225

Calculate minimums in Pandas without `zero`-values?

I have a following data and need on first step to find min values among rows without 0.00

HOME_48  HOME_24  HOME_12  HOME_03  HOME_01  HOME_00   HOME  
   0.00     1.54     2.02     1.84     1.84     1.84   1.84  
   0.00     1.47     1.76     1.89     2.56     2.56   2.56  
   0.00     2.02     2.50     2.56     1.89     1.92   1.92  

Later I need calculate delta-diff between min and max, but if I use below code, the end-results are not acceptable

df['HOME_MIN'] = df.loc[:, COL_HOME].min(axis=1)

I don't want use following tricks:

df = df.replace(0, np.NaN)

Beacuse, sometimes the extreme values can be equal as 0.01, 0.02 - these ones are not correct values also.

How can I add condition to skip 0.00| 0.01 values?

NOTE: correct filter is

df[df[COL_HOME].min(axis=1) > 0.03].loc[:, COL_HOME].min(axis=1)

Upvotes: 8

Views: 18052

Answers (1)

chrisb
chrisb

Reputation: 52276

You could use a boolean filter to exclude whatever you don't want, like this.

In [46]: df[df > .01].min(axis=1)
Out[46]: 
0    1.54
1    1.47
2    1.89
dtype: float64

Upvotes: 13

Related Questions