1

I have the following DataFrame:

df1:

   Index   ColA  
     a      10   
     b       9   
     c      12   
     d      13   

df2:

   Index  Letter  Names    
     0      d     Waylon    
     1      a     Marcus 
     2      z     Eddie 
     3      q     Justine 
     4      c     Angela 
     5      b     Joanna 

I want to make to replace the index values in df1 with the corresponding values in df2, so the result would look like:

df1:

   Index   ColA  
   Marcus   10   
   Joanna    9   
   Angela   12   
   Waylon   13   

Any ideas?

1 Answer 1

1

You need rename by dictionary created by set_index with to_dict:

df1 = df1.rename(index=df1.set_index('Letter')['Names'].to_dict())
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Jezrael, thanks for your swift response. I tried this, but keep getting the following error: 'Series' object is not callable. I might be because the column you called Index, is the actual index of the column..Do you know how to solve this?

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.