开发者社区 问答 正文

如何倒转dataframe的行?

如何倒转dataframe的行?

展开
收起
游客y244y7ln2rlpa 2021-12-05 20:27:31 374 分享 版权
1 条回答
写回答
取消 提交回答
  • df = pd.DataFrame(np.arange(9).reshape(3, -1))
    print(df)
    
    # 方法 1
    df.iloc[::-1, :]
    
    # 方法 2
    print(df.loc[df.index[::-1], :])
    
    #>	   0  1  2
    	0  0  1  2
    	1  3  4  5
    	2  6  7  8
    
    #>	   0  1  2
    	2  6  7  8
    	1  3  4  5
    	0  0  1  2
    
    
    2021-12-05 22:22:58
    赞同 展开评论
问答地址: