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?

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
bikuser
  • 2,013
  • 4
  • 33
  • 57

2 Answers2

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'))
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
1

Try this

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