【发布时间】:2019-05-30 21:51:48
【问题描述】:
我有一个数据框,其中包含过去一年特定出发地和目的地的航空公司预订数据。系统中有数百个类似的数据集。
在每个数据集中,数据中都有漏洞。在当前示例中,一年中有大约 85 天没有预订数据。
这里有两列 - departure_date and bookings.
对我来说下一步是to include the missing dates in the date column, and set the corresponding values in bookings column to NaN.
我正在寻找最好的方法。
请在下面找到部分dataFrame:
Index departure_date bookings
0 2017-11-02 00:00:00 43
1 2017-11-03 00:00:00 27
2 2017-11-05 00:00:00 27 ********
3 2017-11-06 00:00:00 22
4 2017-11-07 00:00:00 39
.
.
164 2018-05-22 00:00:00 17
165 2018-05-23 00:00:00 41
166 2018-05-24 00:00:00 73
167 2018-07-02 00:00:00 4 *********
168 2018-07-03 00:00:00 31
.
.
277 2018-10-31 00:00:00 50
278 2018-11-01 00:00:00 60
我们可以看到数据集的期限为一年(2017 年 11 月 2 日至 2018 年 11 月 1 日)。但我们只有 279 天的数据。例如,我们没有 2018-05-25 和 2018-07-01 之间的任何数据。我必须将这些日期包含在离开日期列中,并将相应的预订值设置为 NaN。
对于第二步,我计划使用类似的方法进行一些插值
dataFrame['bookings'].interpolate(method='time', inplace=True)
请建议 Python 中是否有更好的替代方案。
【问题讨论】:
-
我怀疑插值是否准确......
-
确实如此.. 仅用于某些测试目的。现在,我需要知道如何通过在预订列中包含缺失的日期和 NaN 值来准备数据框。似乎有很多方法可以估计缺失的时间序列数据。
标签: python pandas time-series interpolation missing-data