Select DataFrame rows between two dates

前端 未结 10 935
挽巷
挽巷 2020-11-22 03:14

I am creating a DataFrame from a csv as follows:

stock = pd.read_csv(\'data_in/\' + filename + \'.csv\', skipinitialspace=True)

The DataFra

10条回答
  •  梦谈多话
    2020-11-22 04:07

    you can do it with pd.date_range() and Timestamp. Let's say you have read a csv file with a date column using parse_dates option:

    df = pd.read_csv('my_file.csv', parse_dates=['my_date_col'])
    

    Then you can define a date range index :

    rge = pd.date_range(end='15/6/2020', periods=2)
    

    and then filter your values by date thanks to a map:

    df.loc[df['my_date_col'].map(lambda row: row.date() in rge)]
    

提交回复
热议问题