12.1. Exercises
Instructions:
Running a coding exercise for the first time, could take a bit of time for everything to load. Be patient, it could take a few minutes.
When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.
Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.
Practicing Bar Charts
You are going to load the canucks.csv from the questions that we exported as a csv in the last section and create a bar plot of the Positions column.
Tasks:
- Load in the csv named
canucks.csvand save it ashockey_players. - Use
alt.Chart()to create a chart object. - Use
.mark_bar()to create a bar plot. - Use
.encode()to specify thePositioncolumn for plotting. - Assign a color as Teal and set opacity to 0.5.
- Don’t forget to add a title as “Canuck Player Positions”..
Practicing Scatterplots
Ok, let’s try our luck with a scatterplot. We want to explore the relationship between Age and Salary.
Tasks:
- Plots x as
Ageand y asSalaryusing a scatterplot and save the plot in an object namedage_salary_scatter. - Use the
mark_circle(...)to specify a scatter plot. - Set color to
Darkblueand opacity to 0.4. - Don’t forget to assign a title as “Canuck players Age vs. Salary”.