Python 在熊猫中,如何在不添加新列的情况下重置索引?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16167829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 21:55:40  来源:igfitidea点击:

In pandas, how can I reset index without adding a new column?

pythonpandas

提问by waitingkuo

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

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

我的问题是我怎么能reset_index不添加新列index

采纳答案by bdiamante

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

您可以使用中的drop=True选项reset_index()。见这里