FAQ: Merging Datasets - Choosing a Merge Method

This community-built FAQ covers the “Choosing a Merge Method” exercise from the lesson “Merging Datasets”.

Paths and Courses
This exercise can be found in the following Codecademy content:

[Beta] Python for Data Science: Working with Data

FAQs on the exercise Choosing a Merge Method

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

This is the first question:

  1. We’ve loaded two DataFrames. The first, results, contains data on the final score of each game. The second, worldcupgames, lists every game in each FIFA World Cup.

You’ve been asked to use this data to determine the number of goals scored in each FIFA World Cup. Select the most precise method to merge these two DataFrames into a dataset capable of answering that question.

This is the code that i believe to be correct:

YOUR SOLUTION HERE

merged_df = pd.merge(results,
worldcupgames,
left_on = ‘date’,
right_on = ‘date’,
how = ‘inner’)

show output

merged_df.head()

Results uising this code:

My point of view:
I believe that im possibly missing code for the count of goals scored

hey there, i believe you’re missing matches and having some random results because your left_on and right_on statements should contain lists with the date, home_team and away_team to merge or join both of the tables exactly how we need to

I´m being asked to merge this two tables results and worldcupgames,
I need to know how many goals were scored in each world cup, so my code is the following

merged_df = pd.merge(left = worldcupgames, right = results,
left_on = [‘date’, ‘home_team’, ‘away_team’],
right_on = [‘date’, ‘home_team’, ‘away_team’],
how = ‘left’)

since i just need the world cup games to then assign a result for each, i choosed to put the left table as worldcupgames and use a left merge, this should just do the work, keeping me with all the matches from worldcup, but i get this message

Thanks my g, i can’t remember what the answer was, but i got it figured out. Also didn’t realize that there is a ‘solution’ button. Hope your coding journey is going well!!

Like he mentioned there is a solution button if you click on the “get unstuck” button in the upper right hand corner.
image