在 pandas 中,如何在不添加新列的情况下重置索引? [英] In pandas, how can I reset index without adding a new column?

查看:65
本文介绍了在 pandas 中,如何在不添加新列的情况下重置索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

In [37]: df = pd.DataFrame([[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]])

In [38]: df2 = pd.concat([df, df])

In [39]: df2.reset_index()
Out[39]: 
   index  0  1  2  3
0      0  1  2  3  4
1      1  2  3  4  5
2      2  3  4  5  6
3      0  1  2  3  4
4      1  2  3  4  5
5      2  3  4  5  6

我的问题是,如何在不添加新列index的情况下reset_index?

My problem is that how can I reset_index without adding a new column index?

推荐答案

您可以在reset_index()中使用drop=True选项.请参见此处.

You can use the drop=True option in reset_index(). See here.

这篇关于在 pandas 中,如何在不添加新列的情况下重置索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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