【发布时间】:2021-03-29 03:55:33
【问题描述】:
我有一个包含日期时间和值的大数据框,所以我将采用一个名为 df1 的示例数据框
DateTime Values
2020-12-26 14:00:00 439.0
2020-12-26 14:00:00 441.0
2020-12-26 14:00:00 461.0
2020-12-27 08:00:00 536.0
2020-12-27 08:00:00 547.0
2020-12-27 08:00:00 484.0
2020-12-27 08:00:00 497.0
2020-12-27 14:00:00 491.0
2020-12-27 14:00:00 512.0
2020-12-27 14:00:00 529.0
2020-12-27 14:00:00 436.0
我还有另一个完整的数据框 df 2
DateTime Trend
2020-12-18 14:00 no trend
2020-12-19 08:00 no trend
2020-12-19 14:00 no trend
2020-12-21 08:00 no trend
2020-12-21 14:00 no trend
2020-12-22 08:00 no trend
2020-12-22 14:00 decreasing
2020-12-23 08:00 no trend
2020-12-23 14:00 no trend
2020-12-24 08:00 no trend
2020-12-24 14:00 no trend
2020-12-25 08:00 no trend
2020-12-25 14:00 decreasing
2020-12-26 08:00 no trend
2020-12-26 14:00 decreasing
2020-12-27 08:00 no trend
2020-12-27 14:00 no trend
我正在尝试创建一个新列 df1[Trend] 并根据正确的日期时间分配趋势值
结果应该是这样的
DateTime Values Trend
2020-12-26 14:00:00 439.0 decreasing
2020-12-26 14:00:00 441.0 decreasing
2020-12-26 14:00:00 461.0 decreasing
2020-12-27 08:00:00 536.0 no trend
2020-12-27 08:00:00 547.0 no trend
2020-12-27 08:00:00 484.0 no trend
2020-12-27 08:00:00 497.0 no trend
2020-12-27 14:00:00 491.0 no trend
2020-12-27 14:00:00 512.0 no trend
2020-12-27 14:00:00 529.0 no trend
2020-12-27 14:00:00 436.0 no trend
我有办法吗?
【问题讨论】:
标签: python python-3.x pandas dataframe datetime