LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Pandas Joins for Spreadsheet Users

Kurs anzeigen

Anleitung zur Übung

  • 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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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()
Code bearbeiten und ausführen