python - 在前 4 个字符后按字母顺序对 pandas 数据帧进行排序
问题描述
我有一个这样的数据框
new_col new_elements new_val old_col old_elements old_val
0 0 384444683 593 2 423483819 480
1 1 384444684 594 32 248239340 341
2 2 384444686 596 0 249289049 342
我想要这个:
new_col old_col new_elements old_elements new_val old_val
0 0 2 384444683 423483819 593 480
1 1 32 384444684 248239340 594 341
2 2 0 384444686 249289049 596 342
我知道这df.sort_index(axis=1)
会按字母顺序对我的列进行排序,但它们现在已经按这种方式排序了。我想要的是让它们在前缀之后按字母顺序排序(前 4 个字符)
解决方案
推荐阅读
- ios - Swift:在同一个 UICollectionViewController 中拖放单元格
- google-sheets - 规范化 Google 表格中的数据 - 转置多列填写
- javascript - 如何让 jstree 自动打开第一个树节点的路径(和触发功能)
- sql-server - 选择多个连接查询中相同记录 ID 的第一条记录
- javascript - 即使在浏览器中键入后端 Nodejs url 并显示来自 Oracle 的数据时,Angular 2 中的 404 错误
- css - 引导程序中的不可见导航栏
- javascript - 每次“onclick”时使背景淡入
- r - 问题合并数据框:警告加入因子和字符向量
- swift - 在将 UIImage 中的每个像素值传递给 CoreML 模型之前,是否需要对其进行标准化?
- node.js - 无法访问公用文件夹 Firebase 托管