在大 pandas DataFrame中重新分配索引 [英] Reassigning index in pandas DataFrame

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

问题描述

我相当确定这是一个重复的,但假设我有一个大熊猫DataFrame,我已经根据一些列的值对行进行了排序。最初的索引是整数 0,1,...,n-1 ,但现在它们是乱序的。如何将这些索引重新分配给新排序的DataFrame的正确顺序?

解决方案

df .reset_index(drop = True,inplace = True)


I'm fairly sure this is a duplicate, but suppose I have a pandas DataFrame and I've sorted the rows based on the values of some column. Originally the indices were the integers 0, 1, …, n-1 but now they're out of order. How do I reassign these indices to be in the proper order for the new sorted DataFrame?

解决方案

df.reset_index(drop=True, inplace=True)

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

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