2

I tried this:

pd.date_range(2000, periods = 365, freq = 'D',format = '%d-%m-%Y')

why I am getting this result:

DatetimeIndex(['1970-01-01 00:00:00.000002', '1970-01-02 00:00:00.000002',
               '1970-01-03 00:00:00.000002', '1970-01-04 00:00:00.000002',
               '1970-01-05 00:00:00.000002', '1970-01-06 00:00:00.000002',
               '1970-01-07 00:00:00.000002', '1970-01-08 00:00:00.000002',

Any help?

2 Answers 2

2

You need add '' to 2000 only:

print (pd.date_range('2000', periods = 365, freq = 'D'))

DatetimeIndex(['2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04',
               '2000-01-05', '2000-01-06', '2000-01-07', '2000-01-08',
               '2000-01-09', '2000-01-10',
               ...
               '2000-12-21', '2000-12-22', '2000-12-23', '2000-12-24',
               '2000-12-25', '2000-12-26', '2000-12-27', '2000-12-28',
               '2000-12-29', '2000-12-30'],
              dtype='datetime64[ns]', length=365, freq='D')

If use int, cast it to str:

print (pd.date_range(str(2000), periods = 365, freq = 'D'))
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

pd.date_range('1/1/2000', periods = 365, freq = 'D',format = '%d-%m-%Y')

1 Comment

is it possible to generate date_range if we only provide 2000 instead of 1/1/2000??

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.