我正在处理一个熊猫系列,我想对这些数据进行重采样,以获得10秒的间隔。我正在处理的系列:
volSeries.head(20)
Time
2018-10-14 12:00:00 6.0
2018-10-14 12:00:02 5.0
2018-10-14 12:02:32 6.0
2018-10-14 12:02:57 5.0
2018-10-14 12:03:22 6.0
2018-10-14 12:03:27 5.0
2018-10-14 12:17:42 6.0
2018-10-14 12:17:47 5.0
2018-10-14 12:17:57 5.0
2018-10-14 12:18:07 6.0
2018-10-14 12:18:12 5.0
2018-10-14 12:18:17 6.0
2018-10-14 12:18:32 5.0
2018-10-14 12:18:47 6.0
2018-10-14 12:18:57 5.0
2018-10-14 12:19:27 6.0
2018-10-14 12:19:37 5.0
2018-10-14 12:20:37 6.0
2018-10-14 12:20:57 5.0
2018-10-14 12:21:07 6.0
Name: Value, dtype: float64
当我尝试重新采样时,输出线性增加,与数据不匹配:
volumeResampler = volSeries.resample('10S')
resampledVolumeData = volumeResampler.interpolate('linear')
resampledVolumeData.head(20)
Time
2018-10-14 12:00:00 6.000000
2018-10-14 12:00:10 6.198148
2018-10-14 12:00:20 6.396296
2018-10-14 12:00:30 6.594444
2018-10-14 12:00:40 6.792593
2018-10-14 12:00:50 6.990741
2018-10-14 12:01:00 7.188889
2018-10-14 12:01:10 7.387037
2018-10-14 12:01:20 7.585185
2018-10-14 12:01:30 7.783333
2018-10-14 12:01:40 7.981481
2018-10-14 12:01:50 8.179630
2018-10-14 12:02:00 8.377778
2018-10-14 12:02:10 8.575926
2018-10-14 12:02:20 8.774074
2018-10-14 12:02:30 8.972222
2018-10-14 12:02:40 9.170370
2018-10-14 12:02:50 9.368519
2018-10-14 12:03:00 9.566667
2018-10-14 12:03:10 9.764815
Freq: 10S, Name: Value, dtype: float64
在比较重采样前后的图形时,可以看到它显然没有正确插值
重新采样前:
重新采样后:
误差似乎与我插值的频率有关。我插值的值的间距不一致,相邻点之间的最小间距为2秒,最大间距为37080秒
如果我在任何地方重新采样<;=4秒,插值工作正常。我不确定这是一个bug还是一个特性
如果要使用频率窗口之外的值执行插值,可以在初始数据帧中插入所需频率,对其进行排序,然后执行插值,然后仅选择所需精确频率的值:
这使得:
相关问题 更多 >
编程相关推荐