首页 > 解决方案 > 向前查找没有 NaN 的值,就像 Series.asof

问题描述

我知道 Series.asof 是 .HoweverThe last row without any NaN is taken我想得到The first row without any NaN is taken。有什么办法可以解决吗?

标签: pandas

解决方案


您可以通过以下方式完成此操作:

ser[~ser.isnull()].iloc[0]

或者

ser[ser.isnull().ne(True).idxmax()]

或者使用更惯用的first_valid_index

ser[ser.first_valid_index()]

推荐阅读