给出熊猫的PeriodIndex
x = pd.PeriodIndex(start='1/1/2000', end='12/31/2010', freq='d')
如何选择所有年份一个月中的所有日期
#ppMonth is a pandas Period,
#randomNum is a random day within that month
indexLoc = x.get_loc(str(ppMonth.month) + "/" + str(randomNum) + "/" + str(ppMonth.year))
这很糟糕而且效率低下,只能得到特定年份的价格。
答案 0 :(得分:1)
使用month
x[x.month==10]
Out[455]:
PeriodIndex(['2000-10-01', '2000-10-02', '2000-10-03', '2000-10-04',
'2000-10-05', '2000-10-06', '2000-10-07', '2000-10-08',
'2000-10-09', '2000-10-10',
...
'2010-10-22', '2010-10-23', '2010-10-24', '2010-10-25',
'2010-10-26', '2010-10-27', '2010-10-28', '2010-10-29',
'2010-10-30', '2010-10-31'],
dtype='period[D]', length=341, freq='D')