The pushback of python scrolling at any point in time

Cute Dai Ma 2022-11-08 04:25:53 阅读数:521

pushbackpythonscrollingpointtime

There are several key points:

  1. Loop over time: you can use pandas' date_range function, which is easier
  2. Backward at any point in time: Use relativedelta() of dateutil.relativedelta to push back the exact date

Sample code

For example:

  1. Loop 2020-01-01 to 2020-02-01 this time period
  2. Each round is pushed back 5 months
import pandas as pdfrom dateutil.relativedelta import relativedeltafor start_date in pd.date_range("2020-01-01", "2020-02-01"):end_date = start_date + relativedelta(months=5) # backwardPush for 5 monthsprint("Time interval: start date{} end date{}".format(start_date, end_date))

The results obtained are as follows:

Time range: start date 2020-01-01 00:00:00 end date 2020-06-01 00:00:00Time interval: start date 2020-01-02 00:00:00 end date 2020-06-02 00:00:00Time interval: start date 2020-01-03 00:00:00 end date 2020-06-03 00:00:00Time interval: start date 2020-01-04 00:00:00 end date 2020-06-04 00:00:00Time interval: start date 2020-01-05 00:00:00 end date 2020-06-05 00:00:00Time interval: start date 2020-01-06 00:00:00 end date 2020-06-06 00:00:00Time interval: start date 2020-01-07 00:00:00 end date 2020-06-07 00:00:00Time interval: start date 2020-01-08 00:00:00 end date 2020-06-08 00:00:00Time interval: start date 2020-01-09 00:00:00 end date 2020-06-09 00:00:00Time interval: start date 2020-01-10 00:00:00 end date 2020-06-10 00:00:00Time interval: start date 2020-01-11 00:00:00 end date 2020-06-11 00:00:00Time interval: start date 2020-01-12 00:00:00 end date 2020-06-12 00:00:00Time interval: start date 2020-01-13 00:00:00 end date 2020-06-13 00:00:00Time interval: start date 2020-01-14 00:00:00 end date 2020-06-14 00:00:00Time interval: start date 2020-01-15 00:00:00 end date 2020-06-15 00:00:00Time interval: start date 2020-01-16 00:00:00 end date 2020-06-16 00:00:00Time interval: start date 2020-01-17 00:00:00 end date 2020-06-17 00:00:00Time interval: start date 2020-01-18 00:00:00 end date 2020-06-18 00:00:00Time interval: start date 2020-01-19 00:00:00 end date 2020-06-19 00:00:00Time interval: start date 2020-01-20 00:00:00 end date 2020-06-20 00:00:00Time interval: start date 2020-01-21 00:00:00 end date 2020-06-21 00:00:00Time interval: start date 2020-01-22 00:00:00 end date 2020-06-22 00:00:00Time interval: start date 2020-01-23 00:00:00 end date 2020-06-23 00:00:00Time interval: start date 2020-01-24 00:00:00 end date 2020-06-24 00:00:00Time interval: start date 2020-01-25 00:00:00 end date 2020-06-25 00:00:00Time interval: start date 2020-01-26 00:00:00 end date 2020-06-26 00:00:00Time interval: start date 2020-01-27 00:00:00 end date 2020-06-27 00:00:00Time interval: start date 2020-01-28 00:00:00 end date 2020-06-28 00:00:00Time interval: start date 2020-01-29 00:00:00 end date 2020-06-29 00:00:00Time interval: start date 2020-01-30 00:00:00 end date 2020-06-30 00:00:00Time interval: start date 2020-01-31 00:00:00 end date 2020-06-30 00:00:00Time interval: start date 2020-02-01 00:00:00 end date 2020-07-01 00:00:00
版权声明:本文为[Cute Dai Ma]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2022/312/202211080407176669.html