Module 5 - Practice - Time Series

Back to the course outline

Exercise 1:

Create a numPy datetime variable with today's date. Then create 7 consecutive days (1 week) starting from the variable with today's date.

Exercise 2:

Create a pandas datetime index with the dates 2016-02-11, 2016-07-01, 2016-07-09, 2016-10-08, 2017-02-18, 2017-02-25, 2017-05-02, 2017-08-26, 2017-12-15, and 2018-02-11. Then create a pandas Series with the values 0,1,2,3,4,5,6,7,8, and 9 in a list, with the dates as the index. Get the rows from the year 2017.

Exercise 3:

Convert the following date formats into pandas datetime:

  • datetime(2017, 12, 15)

  • 8th of October 2016

  • 20180211

  • 2017-02-25

  • 2019-Jan-16

Exercise 4:

Using the pandas library, make a time delta range that has five periods with a 1 hour 45 minute interval.

Exercise 5:

Using the pandas library, create a time delta range with 20 business days starting from today's date.

Exercise 6:

From this link, download the "smalltravel.csv" file and upload it to your datasets folder. Then using pandas, read the file into a dataframe. Resample the average speed column by week using the mean, and plot the graph.

Tip: You do not need to add the line style in the plot code.

Exercise 7:

Using the dataframe from the previous exercise, write code to group the moving time column by day of the week, then plot the graph.

Tip: The index list only needs to contain the weekdays. You do not need to add the line style in the plot code.

Back to the course outline