gpt4 book ai didi

python - 从与 1970-1-1 不同的年份开始的日期时间索引

转载 作者:行者123 更新时间:2023-12-01 07:19:31 24 4
gpt4 key购买 nike

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

date_df

df.index

date_index

df_index_date_wrongoutput = pd.to_datetime(df.index, unit="D")
df_index_date_wrongoutput

date_output_wrong

#desired Output

date_desired_output

# EDIT ORIGIN ERROR

origin_error

# EDIT2: date_parameters

date_parameters

最佳答案

to_datetime中使用参数origin :

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

关于python - 从与 1970-1-1 不同的年份开始的日期时间索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57770729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com