gpt4 book ai didi

python - 将两个每日系列合并为一小时系列

转载 作者:行者123 更新时间:2023-11-28 18:37:51 25 4
gpt4 key购买 nike

我有两个每日系列,我必须将它们合并为一个小时系列,第一个系列用于前 12 小时,第二个系列用于剩余时间。

有没有比手动构建列表并将其转换为系列更有效的方法?谢谢

a = pd.Series(np.random.rand(5), pd.date_range('2015-01-01', periods=5))
b = pd.Series(np.random.rand(5), pd.date_range('2015-01-01', periods=5))
c = an hourly series

最佳答案

可能:

>>> b.index += dt.timedelta(hours=12)
>>> pd.concat((a, b), axis=0).sort_index()
2015-01-01 00:00:00 0.150
2015-01-01 12:00:00 0.970
2015-01-02 00:00:00 0.746
2015-01-02 12:00:00 0.937
2015-01-03 00:00:00 0.523
2015-01-03 12:00:00 0.392
2015-01-04 00:00:00 0.606
2015-01-04 12:00:00 0.459
2015-01-05 00:00:00 0.221
2015-01-05 12:00:00 0.029
dtype: float64

并且,ts.asfreq('H', method='ffill') 具有每小时频率。

关于python - 将两个每日系列合并为一小时系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30730718/

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