我有一个以 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.month
与 boolean 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/