gpt4 book ai didi

python - 更改 x 轴而不更改 pandas 中的索引

转载 作者:太空宇宙 更新时间:2023-11-03 19:06:33 25 4
gpt4 key购买 nike

我有一个 DataFrame 'tso':

tso=DataFrame(temp,index=datet)
#tso['Month']=tso.index.month
tso['Year']=tso.index.year
tso['Day']=tso.index.dayofyear
ax=tso.groupby(['Day','Year']).mean().unstack().plot()

这是图片: enter image description here

我想将x轴更改为“月”而不是“日”。当我放大/缩小图形时,x轴会相应变化。

最佳答案

创建一个新的数据框:

tso1=tso.groupby(['Day','Year']).mean().unstack()
#################creat the datetime index#################################
date=[]
for i in range(len(tso1.index)-1):
date.append(parser.parse(num2date(tso1.index[i]).replace(year=2000).isoformat(" ")))
date.append(parser.parse(num2date(tso1.index[len(tso1.index)-2]).replace(year=2000).isoformat(" ")))
######################################################################################################
ax = pandas.DataFrame(tso1.values,index=date).plot()

关于python - 更改 x 轴而不更改 pandas 中的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14570400/

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