Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 452
SpanishBoy Avatar asked Feb 24 '16 17:02

SpanishBoy


People also ask

How do you find the minimum value in pandas?

Pandas DataFrame min() Method The min() method returns a Series with the minimum value of each column. By specifying the column axis ( axis='columns' ), the max() method searches column-wise and returns the minimum value for each row.

How do you find non missing values in pandas?

notna() function detects existing/ non-missing values in the dataframe. The function returns a boolean object having the same size as that of the object on which it is applied, indicating whether each individual value is a na value or not.

How do I get the minimum of two columns in pandas?

Min value between two pandas columns You can do so by using the pandas min() function twice.


1 Answers

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
like image 182
chrisb Avatar answered Nov 14 '22 23:11

chrisb