0

I have this df_player_means, with 5 items:

Pierre-Emerick Aubameyang    0.629630
Sergio Aguero                0.592593
Danny Ings                   0.555556
Mohamed Salah                0.538462
Sadio Mane                   0.500000

And this df_player_colors, where all players and their respective colors appear multiple times, with 15k items:

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

How do I filter df_player_colors, (or map df_player_means to df_player_colors), ending up with df_player_unique_colors, with players from df_player_means, in that exact sorted order, alongside their respective colors?

I have tried:

 players = df_player_means.index

 df_player_unique_colors = df_player_colors[df_player_colors.index.isin(players)]

But colors being mapped are wrong..

1 Answer 1

2

IIUC, try with join and drop_duplicates maybe if you have duplicated colors for same player

df_player_means.to_frame(name='mean')\
               .join(df_player_colors.to_frame(name='color'), how='left')\
               .drop_duplicates()

or maybe with loc like:

df_player_colors.loc[df_player_means.index]
Sign up to request clarification or add additional context in comments.

2 Comments

oh, I get 'Series' object has no attribute 'join'
@8-BitBorges if they are Series, then use to_frame to be able to use join, see the edit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.