gpt4 book ai didi

python - 更改 pandas resample 中的周定义

转载 作者:行者123 更新时间:2023-11-30 23:05:12 26 4
gpt4 key购买 nike

目前,当我使用 pandas 重新采样功能数天到数周时,它使用星期日到星期六的周,但我希望它使用星期一到星期日的周。这可能吗?我尝试使用文档中的 loffset ,但它根本不会更改数据。

pivot_news =ivot_news.resample('w', 'sum')

最佳答案

您需要freq='W-MON'。例如:

>>> dates = pd.Series(np.arange(30),
... index=pd.date_range('2015-10-1', periods=30, freq='D'))

>>> dates.resample('W', 'sum')
2015-10-04 6
2015-10-11 49
2015-10-18 98
2015-10-25 147
2015-11-01 135
Freq: W-SUN, dtype: int64

>>> dates.resample('W-MON', 'sum')
2015-10-05 10
2015-10-12 56
2015-10-19 105
2015-10-26 154
2015-11-02 110
Freq: W-MON, dtype: int64

您可以找到更多信息in the Pandas docs

关于python - 更改 pandas resample 中的周定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33289200/

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