我有这个df_player_means
,有5个项目:
Pierre-Emerick Aubameyang 0.629630
Sergio Aguero 0.592593
Danny Ings 0.555556
Mohamed Salah 0.538462
Sadio Mane 0.500000
这是df_player_colors
,其中所有玩家及其各自的颜色多次出现,有15k项:
Andrew Robertson #CE1317
Dejan Lovren #CE1317
Joel Matip #CE1317
Joseph Gomez #CE1317
Nathaniel Phillips #CE1317
...
Michail Antonio #7C2C3B
Nathan Holland #7C2C3B
Pablo Fornals #7C2C3B
Robert Snodgrass #7C2C3B
Tomas Soucek #7C2C3B
如何精确过滤df_player_colors
(或将df_player_means
映射到df_player_colors
),最后以df_player_unique_colors
和df_player_means
的玩家排序顺序,以及它们各自的颜色?
我尝试过:
players = df_player_means.index
df_player_unique_colors = df_player_colors[df_player_colors.index.isin(players)]
但是映射的颜色是错误的。
答案 0 :(得分:2)
IIUC,请尝试使用join
和drop_duplicates
,如果您为同一位玩家重复使用颜色
df_player_means.to_frame(name='mean')\
.join(df_player_colors.to_frame(name='color'), how='left')\
.drop_duplicates()
或类似loc的
df_player_colors.loc[df_player_means.index]