1

I'd like to add two columns to an existing dataframe from another dataframe based on a lookup in the name column.

Dataframe to update looks like this:

Player School Conf Cmp Att
Danny Wuerffel Florida 1 708 1170
Steve Sarkisian Brigham Young 0 528 789
Billy Blanton San Diego State 0 588 920

And I'd like to take the height and weight from this dataframe (actually a json file) and add it based on matching Player names:

Name School Conf Height Weight Pct Yds
Danny Wuerffel Florida 1 6-2 217 60.5 10875
Steve Sarkisian Brigham Young 0 6-3 230 66.9 7464
Billy Blanton San Diego State 0 6-0 222 63.9 8165

Codewise I tried something like this so far:

existing_dataframe['Height'] = pd.Series(height_weight_df['Height'])

But I'm missing the part matching them on the name because the DFs aren't in the same order

1 Answer 1

2

Let us try

existing_dataframe = existing_dataframe.merge(height_weight_df[['Name','School','Height','Weight']],left_on=['Player','School'],right_on=['Name','School'],how='left')
Sign up to request clarification or add additional context in comments.

3 Comments

Won't this add all columns from the height_weight_df though?
@MJ95 filter it before merge
sorry, I'm a python newbie, how would that be done?

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.