gpt4 book ai didi

python - 最近日期的滞后 Pandas 时间序列

转载 作者:行者123 更新时间:2023-12-01 09:27:46 25 4
gpt4 key购买 nike

我有一个时间序列如下:

enter image description here

我想通过选择(t - 1 个月)的最近值将 A 列滞后一个月。

例如,A' 作为滞后列 A,其行 1991-02-27 的值对应于 1991-01-30。

Pandas 的解决方案是什么?

最佳答案

您可以将一个月的延迟简化 30 天的延迟并使用 reindex带参数method='nearest':

df = df.reindex(df.index - pd.to_timedelta(30, unit='d'), method='nearest')

关于python - 最近日期的滞后 Pandas 时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50227956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com