Mixing indexes and columns
It's time to look more into player safety! But first, you and the team want to settle a bet on the correlation between (1) the draft round in which a player was chosen and (2) current salary. You were able to find relevant player data from a fantasy football web site through it's API. As is common with APIs, the data returned to you is in JSON format.
The first file has already been loaded to a data frame called current
. You will be loading a second file, draft.json
. As the filename implies, the data file is in JSON format.
This exercise is part of the course
Pandas Joins for Spreadsheet Users
Exercise instructions
- View the first 5 rows of
current
. - Load
draft.json
usingpd.read_json()
and view the first 5 rows. - Merge the two data frames on
player_id
, noting whether it's the index or a data column. - Create a scatter plot of
'draft_round'
vs.'salary_millions'
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# View first 5 rows of 'current'
print(____.head())
# Load `draft.json` and view first 5 rows
draft = pd.____(____, orient='split')
print(draft.____())
# Merge data frames
players = current.merge(____, how='outer', left_index=____, right_on=____)
# Create scatter plot
players.plot.scatter(____, 'salary_millions')
plt.show()