4.1. Exercises

Datetime Questions

Practice Processing Dates

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.

Use the output of the following code chunk to help answer the next question.

Let’s read in data and parse a datetime column as well as calculate the hockey team’s oldest and youngest player.

Tasks:

  • Read in the canucks.csv file from the data folder and parse the Birth Date column. Save this as an object named canucks.
  • Find the oldest player’s date of birth and save the Timestamp as oldest.
  • Find the youngest player’s date of birth and save the Timestamp as youngest.
  • Find the age difference between the two players in years to 2 decimal places. Save this as an object name age_range.
  • Display age_range.
Hint 1
  • Are you using the argument parse_dates while reading in the data?
  • The oldest player has the min() date of birth.
  • The youngest player has the max() date of birth.
  • Are you subtracting the min value from the max value?
  • Are you rounding to 2 decimal places?
Fully worked solution: