cliffgao的个人博客分享 http://blog.sciencenet.cn/u/cliffgao 兴趣:生物信息学、统计、概率

博文

pandas 将 行号(index索引号)转化为新的列

已有 11543 次阅读 2020-5-5 23:30 |个人分类:python|系统分类:科研笔记| pandas

pandas 将 行号(index索引号)转化为新的列

参考: https://stackoverflow.com/questions/20461165/how-to-convert-index-of-a-pandas-dataframe-into-a-column


import pandas as pd

如果是多个索引列,使用 df.reset_index(level=['indexname'])


图片.png


如果是单个索引值

df['NewColName']=df.index

图片.png



https://wap.sciencenet.cn/blog-468005-1231765.html

上一篇:numpy 产生重复的数、一维向量。
下一篇:全国生物信息学学会组织
收藏 IP: 111.165.11.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-29 16:25

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部