python pandas Generation Time List

  • 2021-07-06 11:14:13
  • OfStack

python Generates 1 Date List

Import pandas first


import pandas as pd
def get_date_list(begin_date,end_date):
date_list = [x.strftime('%Y-%m-%d') for x in list(pd.date_range(start=begin_date, end=end_date))]
return date_list
###  Can be tested 
print(get_date_list('2018-06-01','2018-06-08'))
#### ['2018-06-01', '2018-06-02', '2018-06-03', '2018-06-04', '2018-06-05', '2018-06-06', '2018-06-07', '2018-06-08']

Of course, the format of date can be modified according to your own needs, and the format of passed-in date can also be modified. freq parameter can be added to pd.date_range function, and the default is' D ', which means day.

pandas is very effective in dealing with time series, and it is easy to use


Related articles: