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.
Cet exercice fait partie du cours
Pandas Joins for Spreadsheet Users
Instructions
- View the first 5 rows of each data frame.
- Inner merge the data with
puntsas the right-hand data frame and view the result
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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()