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.csv and save it as hockey_players.
  • Use alt.Chart() to create a chart object.
  • Use .mark_bar() to create a bar plot.
  • Use .encode() to specify the Position column for plotting.
  • Assign a color as Teal and set opacity to 0.5.
  • Don’t forget to add a title as “Canuck Player Positions”..
Hint 1
  • Are you sure you are using opacity to set the opacity?
  • Are you using the correct Dataframe?
  • Did you assign the correct values to color and opacity?
  • Are you using the .properties(title=...) to assign the title?
  • Are you spelling color in the American manner?
Fully worked solution:

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 Age and y as Salary using a scatterplot and save the plot in an object named age_salary_scatter.
  • Use the mark_circle(...) to specify a scatter plot.
  • Set color to Darkblue and opacity to 0.4.
  • Don’t forget to assign a title as “Canuck players Age vs. Salary”.
Hint 1
  • Are you using .mark_circle()
  • Are you sure you using opacity to set the opacity?
  • Are you using the correct Dataframe?
  • Are you assigning variables x and y to the correct columns
  • Did you assign the correct values to color, title and opacity?
  • Are you spelling color in the American manner?
Fully worked solution: