Get startedGet started for free

Completing a one-to-many merge

With the hard work out of the way, it's time to merge those tables. You'll be joining game_matchups and punts. You might recall that earlier you determined the data frames are ready to go. All that's left is to refresh your memory with a quick look and then write the code.

After merging the data, we can determine the number of games that had a certain number of punts by grouping by GameKey and then counting the number of entries in the PlayId column. The code has been provided for you.

This exercise is part of the course

Pandas Joins for Spreadsheet Users

View Course

Exercise instructions

  • View the first 5 rows of each data frame.
  • Inner merge the data with punts as the right-hand data frame and view the result

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# View first 5 rows of each data frame
print(____.head(), '\n', ____.head())

# Merge data frames 
games_all = ____.merge(____, how='____')
print(____.head(10))

# Produce counts of games by number of punts
counts = games_all.groupby('GameKey')['PlayId'].size()
counts.hist() 
plt.xlabel("Punts per Game")
plt.ylabel("Number of Games")
plt.show()
Edit and Run Code