Pandas 索引项 问题 (行号)
2020-4-28 14:12
阅读:6284
标签:pandas
import pandas as pd
(1)Pandas 遇到 cannot handle a non-unique multi-index
可能是因为索引项不唯一造成的,去掉重复的索引即可。
(2)pandas dataframe 去掉重复的行
df=df.loc[~df.index.duplicated(keep='first')]
(3)pandas 去掉特殊列重复项;
先产生数据框
以A,B两列为ID; 有两个重复项 1,a, 1,a 去掉一项; 默认情况是keep='frist'
运行下面命令, 去掉了第一行。但行号从0 跳到了2.
reset_index()之后,行号从0-3 正常; 但多了原来的行号0,2,3,4;
。
添加drop=True ; reset_index(drop=True)
转载本文请联系原作者获取授权,同时请注明本文来自高建召科学网博客。
链接地址:https://m.sciencenet.cn/blog-468005-1230568.html?mobile=1
收藏
当前推荐数:0
推荐到博客首页
网友评论0 条评论