重新分配数据帧的索引 [英] Reassign index of a dataframe

查看:37
本文介绍了重新分配数据帧的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据框:

Month
1    -0.075844
2    -0.089111
3     0.042705
4     0.002147
5    -0.010528
6     0.109443
7     0.198334
8     0.209830
9     0.075139
10   -0.062405
11   -0.211774
12   -0.109167
1    -0.075844
2    -0.089111
3     0.042705
4     0.002147
5    -0.010528
6     0.109443
7     0.198334
8     0.209830
9     0.075139
10   -0.062405
11   -0.211774
12   -0.109167
Name: Passengers, dtype: float64

如您所见,数字从 1-12/1-12 列出了两次,相反,我想将索引更改为 1-24.问题是在绘制它时,我看到以下内容:

As you can see numbers are listed twice from 1-12 / 1-12, instead, I would like to change the index to 1-24. The problem is that when plotting it I see the following:

plt.figure(figsize=(15,5))
plt.plot(esta2,color='orange')
plt.show()

我希望看到一条从1到24的连续线.

I would like to see a continuous line from 1 to 24.

推荐答案

esta2 = esta2.reset_index() 会给你 0-23.如果您需要1-24,则只需执行 esta2.index = np.arange(1,len(esta2)+ 1).

esta2 = esta2.reset_index() will get you 0-23. If you need 1-24 then you could just do esta2.index = np.arange(1, len(esta2) + 1).

这篇关于重新分配数据帧的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆