[英]Reshape pandas dataframe from column to unique index
如果您只想从索引中删除重复值,请使用:
df = df.set_index('Person')
df.index = np.where(df.index.duplicated(), '', df.index)
您可以创建一个MultiIndex
,将先前的数字索引保持为第二级:
df.set_index(['Person', df.index], inplace=True)
df
Score Type Number
Person
Paul 0 24 A 1
1 23 C 2
2 54 F 3
John 3 64 A 1
4 89 G 2
Mia 5 56 X 1
我认为这是最接近所需 output 的值,因为根据定义,dataframe 的每一行都必须有一个索引值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.