我想根据 NaN 发生的时间使用“mean”和“interpolate”在 df 中填充 NaN。如下所示,第一个 NaN 发生在上午 6 点,第二个 NaN 发生在上午 8 点。02/03/2016 05:00 802/03/2016 06:00 NaN02/03/2016 07:00 102/03/2016 08:00 NaN02/03/2016 09:00 3我的 df 由数千天组成。我想对早上 7 点之前发生的任何 NaN 应用“填充”,并对早上 7 点之后发生的应用“插值”。我的数据是从早上 6 点到下午 6 点。我的尝试是:df_imputed = (df.between_time("00:00:00", "07:00:00", include_start=True, include_end=False)).ffill()df_imputed = (df.between_time("07:00:00", "18:00:00", include_start=True, include_end=True)).interpolate() 但它将我的 df 缩减到指定的时间段,而不是按照我的意愿填充 NaN。编辑:我的 df 包含大约 400 列,因此该过程将适用于所有列。
添加回答
举报
0/150
提交
取消