Python pandas min () does not collect a minimum

I got a strange problem. I am sure there is a logical reason.

I have a dataframe called alloptions which has 4 columns, minage1, minage2, minage3 and minage4, which are all float64. the number of missing values ​​increases from minage1 to minage4.

I create a fifth column that takes a minimum of these four columns:

alloptions['minage']=alloptions.apply(lambda x: min([x['minage1'],x['minage2'],x['minage3'],x['minage4']]),axis=1)

which looked like it was working until I found that on line 47

     minage1    minage2 minage3 minage4 minage      
47     NaN      56.0    NaN      NaN     NaN

using .loc, I highlight this line:

In [10]:

 print alloptions.loc[47,:]
 print alloptions.loc[47,:].dtypes

I get

minage1   NaN
minage2    56
minage3   NaN
minage4   NaN
minage    NaN
Name: 47, dtype: float64
float64

so I am confused by why the function did not pick 56.

Thank you in advance for your help.

+4
source share
1 answer

Python min, nan :

>>> min(1, np.nan)
1
>>> min(np.nan, 1)
nan

min pandas, , nan min. axis, , minageX DataFrame,

df['minage'] = df.min(axis=1)

pandas Python, max, min, sum .., pandas; pandas .

+5

All Articles