Reputation: 91
I am trying to transform my index to a date starting from the year 2000. pd.to_datetime() only allows me to start at 1970.
df = pd.DataFrame({"R1": [90,-92,1,5,8,11,2,2,58,3], "R2": [80,5,1,6,56,14,5,3,2,8]})
df
df.index
df_index_date_wrongoutput = pd.to_datetime(df.index, unit="D")
df_index_date_wrongoutput
#desired Output
# EDIT ORIGIN ERROR
# EDIT2: date_parameters
Upvotes: 1
Views: 273
Reputation: 862591
Use parameter origin
in to_datetime
:
df.index = pd.to_datetime(df.index, unit="D", origin='2000-01-01')
print (df)
R1 R2
2000-01-01 90 80
2000-01-02 -92 5
2000-01-03 1 1
2000-01-04 5 6
2000-01-05 8 56
2000-01-06 11 14
2000-01-07 2 5
2000-01-08 2 3
2000-01-09 58 2
2000-01-10 3 8
Upvotes: 1