2 回答
TA贡献1825条经验 获得超6个赞
您可以使用melt,merge和unstack:
df_out = carry.melt('primary_key')\
.merge(players, left_on='value', right_on='position_ID')\
.set_index(['primary_key','variable'])\
.drop('value', axis=1)\
.unstack()
df_out.columns = [f'{i}{j}' if i != 'position_ID' else f'{i}' for i,j in df_out.columns]
print(df_out)
输出:
position_ID position_ID position_ID Heightposition_1_ID Heightposition_2_ID Heightposition_3_ID Weightposition_1_ID Weightposition_2_ID Weightposition_3_ID
primary_key
a ida ide idg 70 74 76 200 204 206
b idb idb idf 71 71 75 201 201 205
c idc idg idc 72 76 72 202 206 202
d idd idd idh 73 73 77 203 203 207
添加回答
举报