小编Ste*_*era的帖子

熊猫排序并保持索引不变

我遇到问题时,想按列对数据框进行排序

df = pd.DataFrame(np.random.random(5))
df.sort(columns = [0],inplace = True)
df

           0
4   0.275867
1   0.304362
2   0.625837
0   0.741176
3   0.767829
Run Code Online (Sandbox Code Playgroud)

当我对列进行排序时,得到的结果不是我所期望的,我期望索引仍应为0、1、2、3、4,所以我如何获得该结果并使列0保持升序。

sorting indexing series pandas

2
推荐指数
1
解决办法
4343
查看次数

标签 统计

indexing ×1

pandas ×1

series ×1

sorting ×1