1
dateindex = pd.date_range(pd.datetime.today(), periods=4, freq='W', dtype='datetime64[ns]')

to generate some dates.

Can I get something like this to generate dates in the past. I tried -4 but no joy.

Cheers Kevin

1
  • do you want to generate four weeks of dates starting with today starting at midnight Commented Mar 26, 2021 at 14:12

1 Answer 1

1

In date_range 2 of start, end, periods should be specified. It assumes your date to be start, unless you specify otherwise.

pd.date_range(end = pd.datetime.today(), periods=4, freq='W', dtype='datetime64[ns]')

You get

DatetimeIndex(['2017-08-13 13:18:39.525080', '2017-08-20 13:18:39.525080',
           '2017-08-27 13:18:39.525080', '2017-09-03 13:18:39.525080'],
          dtype='datetime64[ns]', freq='W-SUN')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.