How to filter a dataframe of dates by a particular month/day?

前端 未结 3 1095
天涯浪人
天涯浪人 2020-11-30 07:37

So my code is as follows:

df[\'Dates\'][df[\'Dates\'].index.month == 11]

I was doing a test to see if I could filter the months so it only

3条回答
  •  遥遥无期
    2020-11-30 08:27

    In your code there are two issues. First, need to bring column reference after the filtering condition. Second, can either use ".month" with a column or index, but not both. One of the following should work:

    df[df.index.month == 11]['Dates']
    
    df[df['Dates'].month == 11]['Dates']
    

提交回复
热议问题