gpt4 book ai didi

python - 按月切片时间戳

转载 作者:太空宇宙 更新时间:2023-11-04 00:50:05 26 4
gpt4 key购买 nike

我有一个以 pandas 日期戳为索引的系列,我该如何对索引进行切片以便获取特定月份的所有值?

d = {'1993-01-01 00:00:00': 10, '1993-02-01 00:00:00': 12}
s = pandas.Series(d)
s.index = pandas.to_datetime(s.index, utc=True)

最佳答案

我想你可以使用 DatetimeIndex.monthboolean indexing :

print (s[s.index.month == 2])

1993-02-01 00:00:00+00:00 12
dtype: int64

关于python - 按月切片时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37512271/

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