I have below dataframe and I want to compute column-wise min value
import pandas as pd
dat1 = pd.DataFrame({'col1' : [1,2,3,4], 'col2' : [-3, np.nan, 4, 4]})
dat1.min(axis = 1, numeric_only = True)
However for the 2nd row, I was expecting nan
value because col2
has nan
, however I get 2 which is the value of col1
.
Could you please help to correct above code.
By default the NaNs are ignored, you should use skipna=False
:
dat1.min(axis=1, numeric_only=True, skipna=False)
Output:
0 -3.0
1 NaN
2 3.0
3 4.0
dtype: float64