0
给出一个df
这样的:如何通过月份和年份输入过滤带日期时间索引的数据框?熊猫
df=pd.read_csv(PATH + 'Matriz3_fechas.csv',index_col='Fecha',skiprows=0)
df.index = pd.DatetimeIndex(df.index)
注意,出生日期是已经与日期时间格式
Fecha D576972dc305aa D576972dc32e9a D576972dc3590a \
2016-06-01 00:00:00 0.0 0.0 0.1 \
2016-07-01 00:05:00 0.0 0.0 0.1 \
2017-05-01 00:10:00 0.0 0.0 0.1 \
2017-05-01 00:15:00 0.0 0.0 0.1 \
2017-07-01 00:20:00 0.0 0.0 0.1 \
从来就试图通过月份和年份过滤指数**:
df=df[(df.index.month==5)&(matriz.index.year==2017)]
但它不会过滤df
得到:(想要的结果)
Fecha D576972dc305aa D576972dc32e9a D576972dc3590a \
2017-05-01 00:10:00 0.0 0.0 0.1 \
2017-05-01 00:15:00 0.0 0.0 0.1 \
它是如此简单 – Dark
所以'打印(DF .index)'返回'DatetimeIndex'?几个月没有交换? – jezrael
我曾尝试过,但输出的形状我得到它[0行x 3列]而不是[2行x 3列] @jezrael –