For example:
0 1
0 87.0 NaN
1 NaN 99.0
2 NaN NaN
3 NaN NaN
4 NaN 66.0
5 NaN NaN
6 NaN 77.0
7 NaN NaN
8 NaN NaN
9 88.0 NaN
My expected output is: [False, True] since 87 is the first !NaN value but not the maximum in column 0. 99 however is the first !NaN value and is indeed the max in that column.
groupby with first
(May not be 100% reliable )
df.groupby([1]*len(df)).first()==df.max()
Out[89]:
0 1
1 False True
bfill
Or using bfill(Fill any NaN value by the backward value in the column , then the first row after bfill is the first not NaN value )
df.bfill().iloc[0]==df.max()
Out[94]:
0 False
1 True
dtype: bool
stack
df.stack().reset_index(level=1).drop_duplicates('level_1').set_index('level_1')[0]==df.max()
Out[102]:
level_1
0 False
1 True
dtype: bool
idxmax with first_valid_index
df.idxmax()==df.apply(pd.Series.first_valid_index)
Out[105]:
0 False
1 True
dtype: bool
idxmax with isna
df.notna().idxmax() == df.idxmax()
Out[107]:
0 False
1 True
dtype: bool
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With