重新采样DataFrame并插值返回NaN

时间:2020-11-03 18:27:22

标签: python pandas numpy interpolation pandas-resample

我有以下示例DataFrame:

             datetime    r    g    b
1 2020-09-02 12:48:00  251  255  128
2 2020-09-03 09:30:00  255   48   48
3 2020-09-03 12:45:00  251  255  128

我想将其重新采样到某个间隔,并用线性插值填充缺失的值。我得到的是NaN值,而不是期望的结果。我的错误在哪里?

df.set_index('datetime').resample('6H').interpolate()

输出:

                      r   g   b
datetime
2020-09-02 12:00:00 NaN NaN NaN
2020-09-02 18:00:00 NaN NaN NaN
2020-09-03 00:00:00 NaN NaN NaN
2020-09-03 06:00:00 NaN NaN NaN
2020-09-03 12:00:00 NaN NaN NaN

0 个答案:

没有答案