【发布时间】:2021-05-14 21:26:37
【问题描述】:
我想在日历中选择几年的日期。所以我们假设每年的 3 月 25 日到 8 月 25 日。我正在测试这种方法:Filtering data for multiple years by date range given by months and days in pandas dataframe,但它对我不起作用。日期的格式是 datetime64[ns],所以我不太确定出了什么问题。我正在测试不同的方法,最后总是只选择月份,没有日期限制。
这是我的代码 sn-p:
np.random.seed(0)
data = pd.DataFrame({'
date': pd.date_range('1990-01-01', freq='d', periods=10000),
'yield': np.random.randn(10000).cumsum(),
'simulation': np.random.randn(10000).cumsum(),
'Predicted': np.random.randn(10000).cumsum()})
out:
date yield simulation Predicted
0 1990-01-01 1.764 -0.202 0.330
1 1990-01-02 2.164 -1.035 0.330
2 1990-01-03 3.143 0.698 1.148
3 1990-01-04 5.384 0.889 1.576
4 1990-01-05 7.251 0.711 -0.928
...............................................
9995 2017-05-14 -186.162 111.432 -56.764
9996 2017-05-15 -186.119 111.323 -57.349
9997 2017-05-16 -185.602 111.266 -58.861
9998 2017-05-17 -185.635 110.207 -57.884
9999 2017-05-18 -184.337 109.880 -56.628
【问题讨论】: