Filtering Pandas DataFrames on dates

前端 未结 12 1307
时光取名叫无心
时光取名叫无心 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条回答
  •  猫巷女王i
    2020-11-22 16:39

    If you have already converted the string to a date format using pd.to_datetime you can just use:

    df = df[(df['Date']> "2018-01-01") & (df['Date']< "2019-07-01")]

提交回复
热议问题