filter pandas dataframe for past x days

后端 未结 2 1679
醉梦人生
醉梦人生 2021-02-20 06:23

I have a dataframe with a date column that I update daily. I\'d like to create a copy of it with just the past 30 day\'s of data.

I tried the following syntax based on

2条回答
  •  不要未来只要你来
    2021-02-20 06:39

    Try this:

    import datetime
    import pandas as pd 
    
    
    df[df.the_date_column > datetime.datetime.now() - pd.to_timedelta("30day")]
    

    Update: Edited as suggested by Josh.

提交回复
热议问题