【发布时间】:2018-01-02 21:30:15
【问题描述】:
给定一个像这样的df:
df=pd.read_csv(PATH + 'Matriz3_fechas.csv',index_col='Fecha',skiprows=0)
df.index = pd.DatetimeIndex(df.index)
注意,Fecha 已经是日期时间格式的索引**
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 \
【问题讨论】:
标签: python pandas datetime indexing