合并/组合多列后遇到此问题:
df =
Name id id_x id_y age age_x
A 111 111 20
B 112 112 30
C 113 113 40 40
我的目标是像这样清理它们:
Name id age
A 111 20
B 112 30
C 113 40
提前谢谢您!
最佳答案
df.groupby(df.columns.str.split('_').str[0],1).first()
Out[1196]:
Name age id
0 A 20.0 111.0
1 B 30.0 112.0
2 C 40.0 113.0
关于python - 在Python中连接/组合相似的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47580397/