 The purpose of this video is not to teach time series. It's just to give a taste of it I'm just going to walk through a script that shows how to plot some time series data I hope that this at least wets your appetite or you'll find out that time series data is not for you And that's fine. Also a Couple things to note here is that you'll have to pip install plot 9 and with plot 9 comes this M-I-Z-A-N-I package. This is going to be the package I use for plotting. I've included some data in this repository This is a tourism data. It comes from the tipple package This data has quarter region state purpose and trips We're just going to filter on One region one state and one purpose just to keep the data set manageable In future videos, I'll show how to operate on on multiple groups, but we're going to keep this simple for now So what I want to show here is that the DS column is All it's doing is taking the quarter column and making it a year dash quarter And this is so that it's easier to feed into the PD dot to date time function on the next line The PD dot to underscore date time function is one of the most common functions you use when you're doing time series analysis Looks like you need to add a space here between my lines Or just select the lines. I'm interested in and then send to the terminal. There we go. So the DS Column is now a date time Object and this makes it easier for other date time functions to work with You'll see it's a year month date and the final line. I just added year Lower in the script I grouped by year to just look at averages and sanity deviation But the main idea is I just wanted to show that there's this DS dot DT dot Something here. I did year, but you can do you can do other functions to create things like a weekdays or Day of week month those kinds of things So this next chunk of code. These are just kind of a descriptive statistics I want to know what the minimum time is or the maximum time I want to know for what my Y is which is strips here what the max strips are what the min trips are and Also the range of my time series. So the minimum date starts in 1998 0101 the max date is 2017 10 1 the max 242 the min 68 and then the range is 7213 days So that kind of gives me a sense of what is in the data set first I'm going to set a theme. This is a plot 9 This is 538 and I'm going to hand wave over this plotting code I'll go in a little bit more detail at the bottom and this gives a nice 538 looking Time series plot. I'm going to adjust the axis of dates here. I don't want them pointing up Straight like that. I'm going to make them kind of tilt So to do that I'm going to go to line 33 and adjust the angle from 90 to 45 Then I'm going to run this chunk again, and you can see that my dates are now tilted So that's just to give a little preview As to how plot 9 works. I think it's really convenient for doing time series plots All right, so now into some some more statistics here, so we're just going to group by Year and get the mean standard deviation and median It's nice to get a sense if you think that there's some seasonality in the data to just kind of look for that So you group by different time aggregations here. It's year lots of times in the world when you when you have Daily data you'll group by things like Mondays Tuesdays Wednesdays to get a sense of the weekly Seasonality, but there could be multiple sources of seasonality also. Maybe there's yearly seasonality monthly seasonality and daily seasonality But the purpose here is just to show how to do group by and take a look at things like mean and standard deviation for a For some kind of time label now in this chunk from line 45 Down to about 49. I'm going to make a moving average Column a lag column and an exponentially weighted moving average column So to do this for moving average There's a function called rolling and the parameter of window which says how many consecutive or contiguous blocks of time you want to include in your mean and Then for the lag, there's a shift function and there you just pass how many continue contiguous blocks of time You want to shift by and then for the exponential moving average EWM. I think the M stands for mean I'm taking the lag and then running an exponential moving Average on it with a parameter of 0.8. That's a parameter to control how much you want to exponentially weight your Your time series lots of details there. I'm again just gonna hand wave over that But I do want to show what this looks like in a plot I'm gonna write this data then I'm gonna make a color palette and in this color palette I'm gonna have a color for the moving average The lag and the exponential Waiting, okay, so I'm gonna talk about this these plotting functions And a little bit more detail right now So this is really similar to GG plot the grammar graphics It's really convenient if you've used GG plot before if you haven't The idea here is that you're building a plot by layers So you have GG plot where x-axis is defined as DS your y-axis is trips And I also want not points only but also a line to to represent trips I want a point in a line for the moving average Using color palette at index 0. I want a point in a line for the exponential moving average using the color palette at index 1 and a point and a line for the lag 8 and Then these are just some more details to get the plotting to look nice for dates or time series data So let's go ahead and run this and here's the plot So I realized that I didn't label What hex number is associated with which color so really quick? I'm just gonna add the colors to the script. I'm gonna go to Wolfram alpha So ee 1d 5 2 this is red F2d 8 0 3 is yellow and 6 9c 9d 0 is blue So this should give you a taste of time series data and time series plotting At least you have a sense of what time series is and some functions you can use to work with it and thanks for watching