weixin_45403415 2019-07-14 00:39 采纳率: 100%
浏览 3770
已采纳

Dataframe数据如何按行调整位置?

问题解决了,用了这里的方法:

https://stackoverflow.com/questions/25817930/fastest-way-to-sort-each-row-in-a-pandas-dataframe

图片说明

如果问题可以由R或者Excel里解决也请分享.

数据由csv或者txt读入dataframe,其中的某些行顺序不对,比如图里4,5,6,7行相应的绿色应该移到红色前面,红色顺延。

目前dataframe:

Row#4: col1 - col2 - col3 - col4 - col6 - col5 - col7

Row#5: col1 - col2 - col3 - col5 - col6 - col7 - col4

Row#6: col1 - col2 - col4 - col5 - col6 - col3 - col7

Row#7: col1 - col3 - col4 - col2 - col5 - col6 - col7

期望dataframe:

Row#1: col1 - col2 - col3 - col4 - col5 - col6 - col7
...

Row#n: col1 - col2 - col3 - col4 - col5 - col6 - col7

  • 写回答

1条回答 默认 最新

  • weixin_45403415 2019-07-14 04:34
    关注

    问题解决了,用了下面的方法:每行排序再变回dataframe。

    https://stackoverflow.com/questions/25817930/fastest-way-to-sort-each-row-in-a-pandas-dataframe

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部