1

i'm trying get better at Python and decided to do some analysis on one of my passions. Wrestling! In this case, Japanese Wrestling!

Basically I'm trying to update values in one data frame from another data frame. Here's what my first data frame looks like

|   | Wrestler          | Matches | DMR |
| 0 | TETSUYA NAITO     | 9       | 0   |
| 1 | HIROSHI TANAHASHI | 9       | 0   |
| 2 | BAD LUCK FALE     | 9       | 0   |
| 3 | KOTA IBUSHI       | 9       | 0   |
| 4 | ZACK SABRE JR.    | 9       | 0   |
| 5 | HIROOKI GOTO      | 9       | 0   |
| 6 | TOMOHIRO ISHII    | 9       | 0   |
| 7 | TOGI MAKABE       | 9       | 0   |
| 8 | YOSHI-HASHI       | 9       | 0   |
| 9 | YUJI NAGATA       | 9       | 0   |

The column I'm trying to update is DMR*(Dave Meltzer Ratings)* from another data frame that is generated from some data I input:

| Wrestler          | DMR      |
| BAD LUCK FALE     | 3.166667 |
| HIROOKI GOTO      | 3.694444 |
| HIROSHI TANAHASHI | 4.111111 |
| KOTA IBUSHI       | 4.222222 |
| TETSUYA NAITO     | 4        |
| TOGI MAKABE       | 3.611111 |
| TOMOHIRO ISHII    | 4.25     |
| YOSHI-HASHI       | 3.638889 |
| YUJI NAGATA       | 4.138889 |
| ZACK SABRE JR.    | 3.611111 |

I have a feeling it's something simple but I couldn't find anything that would explain how to do it. Any help on this would be greatly appreciated.

Thanks, Shan

2 Answers 2

1

Use map by Series:

df1['DMR'] = df1['Wrestler'].map(df2.set_index('Wrestler')['DMR'])

Or merge with left join and drop for remove column:

df1 = pd.merge(df1.drop('DMR', axis=1), df2, how='left')

print (df1)
            Wrestler  Matches       DMR
0      TETSUYA NAITO        9  4.000000
1  HIROSHI TANAHASHI        9  4.111111
2      BAD LUCK FALE        9  3.166667
3        KOTA IBUSHI        9  4.222222
4     ZACK SABRE JR.        9  3.611111
5       HIROOKI GOTO        9  3.694444
6     TOMOHIRO ISHII        9  4.250000
7        TOGI MAKABE        9  3.611111
8        YOSHI-HASHI        9  3.638889
9        YUJI NAGATA        9  4.138889

Notice:

Values in Wrestler column in df2 have to be unique.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Jezrael, I was familiar with map but couldn't get it to work, Appreciate the quick reply and the values in df2 are unique so no issues there!
0

So I am going to assume your first dataframe is called df1 and your second one is called df2. Then this would work:

df1 = df1.drop('DMR', 1)
df = merge(df1, df2, on = 'Wrestler')

Just drop DMR from the first dataframe and then merge them on the Wrestler column.

Comments

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.