python - 无法在 python DataFrame 中的索引中删除重复项
问题描述
我正在尝试删除多索引 python 中的重复索引pandas
dataframe
import pandas as pd
arrays=[['i1', 'i2', 'i3'], ['j1', 'j2', 'j3']]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
df=pd.DataFrame({'a':['b', 'c', 'd']}, index=index)
df = df.groupby(df.index).first()
print(df)
但索引中的重复项尚未删除:
a
(i1, j1) b
(i2, j2) c
(i3, j3) d
我怎么做?
预期输出:
a
(i1, j1) b
(i2, j2) c
解决方案
推荐阅读
- embedded - MCU SPI 在主模式下启用软件从管理,从是第三方 zigbee 设备,它希望其 nSSL 由外部驱动
- python - 如何为输出中的数据创建列?
- json - JSON.parse() 为局部变量和全局变量返回不同的值
- python - 图论 DFS 获取从开始到结束节点的路径
- asp.net-core - EFCore 添加默认阴影属性
- python - 有没有办法在另一台服务器上运行 python 脚本?
- arrays - Mongodb node.js 组织数组结果
- php - How to use a text file to log users in
- javascript - 使用基于实例的装饰器发布订阅者模式“this”始终未定义
- android - 如何重新绑定到正在运行的服务?