how do I convert a series of numbers(0 to 881) into a date. example :
n= [0,1,2,3,....881]
output = 01-01-2015 to somewhat 25-05-2017 .
It doesn't matter what's starting date is . i just want to convert the number column into a date .
Here is one way:
xs = [0, 1, 2, 3, 4, 5]
pd.to_datetime(xs, unit='D', origin='2019-12-29')
# result
DatetimeIndex(['2019-12-29', '2019-12-30', '2019-12-31', '2020-01-01',
'2020-01-02', '2020-01-03'],
dtype='datetime64[ns]', freq=None)
Result is a DatetimeIndex, which you can assign to a column in a data frame.
You can use
timedelta
to covert numbers to date with respect to the initial date.CODE
OUTPUT