
Working with Times Series
Read It: Working with Time Series
Working with time series requires us to work with DateTime objects, which is a special data type in python. Below, we will present three videos that walk you through various ways to plot time series, as well as how to create and work with DateTime objects.
Watch It: Video - Basic Line Plots (2:56 minutes)
Click here for a transcript.
Credit: © Penn State is licensed under CC BY-NC-SA 4.0(link is external)
Watch It: Video - Creating and Working with DateTime Objects (7:01 minutes)
Click here for a transcript.
Credit: © Penn State is licensed under CC BY-NC-SA 4.0(link is external)
Watch It: Video - Using Statistics Within a Time Series Plot (5:29 minutes)
Click here for a transcript.
Credit: © Penn State is licensed under CC BY-NC-SA 4.0(link is external)
Try It: Apply Your Coding Skills in Google Colab
- Click the Google Colab file used in the video is here(link is external).
- Go to the Colab file and click "File" then "Save a copy in Drive", this will create a new Colab file that you can edit in your own Google Drive account.
- Once you have it saved in your Drive, use the partial code below to create scatter plots using plotnine/ggplot.
Note: You must be logged into your PSU Google Workspace in order to access the file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | from plotnine import * # import the library # fill in the blank (...) to plot a line plot with 'Date' on the x-axis and 'Produced (kWh)' on the y-axis ggplot(solar) + ... # fill in the blank (...) to subset all times > '2021-09-08' and < '09-09-2021' solar_subset = solar[(solar[ 'DateTime' ] > ...) ... (solar[ 'DateTime' ] < ...)] # fill in the blank (...) to plot a line plot with 'DateTime' on the x-axis and 'Produced (kWh)' on the y-axis ggplot(solar_subset) + ... # fill in the blank (...) to plot the average hourly 'Produced (kWh)' with a 95% confidence interval ribbon (ggplot(solar) + stat_summary(..., geom = ..., fun_y = np.mean) + stat_summary(..., geom = ..., fun_data = 'mean_cl_boot' , alpha = 0.5 ) ) |
Once you have implemented this code on your own, come back to this page to test your knowledge.