Filtering Pandas DataFrames on dates

前端 未结 12 1312
时光取名叫无心
时光取名叫无心 2020-11-22 16:15

I have a Pandas DataFrame with a \'date\' column. Now I need to filter out all rows in the DataFrame that have dates outside of the next two months. Essentially, I only need

12条回答
  •  天命终不由人
    2020-11-22 16:56

    I'm not allowed to write any comments yet, so I'll write an answer, if somebody will read all of them and reach this one.

    If the index of the dataset is a datetime and you want to filter that just by (for example) months, you can do following:

    df.loc[df.index.month = 3]
    

    That will filter the dataset for you by March.

提交回复
热议问题