ComeçarComece de graça

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.

Este exercício faz parte do curso

Pandas Joins for Spreadsheet Users

Ver curso

Instruções do exercício

  • 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

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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()
Editar e executar o código