python-3.x - Pandas 中的数据框索引转换
问题描述
我想转换以下数据框:
ID 1234
type band category
0 A B C
至:
ID type band category
1234 A B C
其中 ID 是索引列
解决方案
尝试
df.stack(0).reset_index().drop('level_0', axis=1)
输出:
ID Type band category
0 1234 A B C
推荐阅读
- hyperledger-fabric - 可以在单个组织中的 2 个对等方之间创建私有数据吗?超级账本结构
- javascript - 如何在 React Native 后台调用 api
- mysql - 如何修复不准确计数的移动平均线的 SQL 查询
- c# - 在我的正则表达式检测链接中解决灾难性回溯?
- macos - macOS 应用程序:不要让同步更改覆盖用户输入
- xslt - XSLT 计数元素子节点(多个子节点)具有特定值
- python - 如何在带有 Django 项目的 Python 中修复“模块”对象不可迭代的错误
- awk - 将文本块中的第一行与块中的每一行合并
- django - Django单元测试:分离单元测试而不多次查询数据库
- httprequest - 获得 CIO-1 的有效方法?