OK, so in this lecture, we will be looking at the CoLab notebook for profit, the first step in our
notebook will be to install profit since it does not come preinstalled in CoLab.
The next step is to import our usual libraries, this time including profit.
The next step is to download our data, so this data comes from a Kaggle data set, which is for Rassman
store sales, according to Kagle.
This is a drug store in Europe with over three thousand locations, will be looking at one, although
you could do the same analysis on the total sales if you wanted.
OK, so the next step is to read in our CCV using PD that reads GSV.
The next step is to call the head to see what our data looks like.
OK, so let's look at these columns first, we have store, which you can see is an ID, so you'll have
a unique integer for every store.
We'll be focusing on the store with one.
But of course, you can choose your own if you like.
The next column is the day of week.
We won't be using this column since pandas can already infer the day of week from the date.
The next column is sales.
So this is the column that represents our Time series.
The next column is customers, of course, you could potentially use this as a time series as well,
or you could even combine these somehow like the sales per customer.
The next column is open, which tells us whether or not the store was open.
The next column is promo, which tells us whether or not the store was having a promo.
The next two columns are for state holiday and school holiday, which will tell us whether or not these
were happening on those days.
The next step is to plot the sales for store one.
OK, so this time series is kind of interesting, it seems to have several seasonal components at different
scales.
In addition, there seems to be this weird thing where the sales go down to zero very frequently.
So the next step is to count how many of these values are zero.
So as you can see, we have one hundred sixty one zeros.
The next step is to select only the rows of the data frame for store one.
We'll make a copy, which will make it easier for us to update this data frame later in this notebook.
Now, your suspicion may be that the reason the sales are going down to zero, clearly following some
pattern, is that the store is not actually open on these days.
So in the next block, we're going to plot the sales, but only for the day is the store was open.
OK, so as you can see, the Time series now looks much more reasonable, note that we don't particularly
want to model the sales for the days when the store is not open.
We already know when the store is not open and we already know that the sales will be zero on these
days.
So there is no need to predict the time series when the store is closed.
We already know precisely what the value will be.
I know that there are several ways to check that the sales will be zero, although these are not necessarily
equivalent.
What we will show is that when the sales are zero, this is the same as when the customers are zero,
which is the same as when the store is not open.
Of course, this is not necessarily true, but it allows us to be lazy when we choose the relevant values
for our Time series.
For example, the store could be open, but we simply have no customers or we might count customers
even though they do not result in sales, although it's not clear how exactly the customers were counted.
In any case, we can see that all these signals correspond.
What this also means is that every day this door was open, we had non-zero sales and nonzero customers.
So the next step is do call store one head to check our data frame.
Of course, we see that it has the same format as before, but the story is always one.
OK, so the next step is not necessary, but recall that in pandas, we normally like to have the date
as the index when we are looking at a Time series.
Previously, this wasn't possible because we had multiple of the same date since we had multiple stores.
But since we now only have one store, all the dates should be unique.
So the next step is to convert the date column into date time format.
The next step is to set the index of the data frame to date.
The next step is to call store one head again to see how our data frame has changed.
OK, so notice that our date column is now gone and the date is now just an index.
This actually means we'll have more work to do later since, as you recall, profit needs of the date
as a column, not an index.
However, in the next block of code, you can see that this makes the plot of the TIME series more reasonable.
Specifically on the x axis, we now have the date instead of just random integers.
OK, so the next step is to convert our data frame into the format we need for profit.
We'll start by making a copy of the sales column from store one.
As you recall, we would also like to have the date as a column as well.
The next step is to call DFPS head.
One thing to notice about this data frame is that the dates go in reverse chronological order.
This is not a problem since profit actually reads the dates, but it's easier to have them in the usual
format.
Also, notice that the final date of our Time series is two thousand fifteen seven thirty one.
The next step is to call DFPS ducktail.
So as you can see, the first date in our Time series is January 1st, 2013.
So since we'd like to have our data frame in chronological order, the next step is to call it index.
Now, let's call the head function again.
By the way, we can see here where the zeros are, the first zero is on New Year's Day, which, of
course is a holiday.
After this, we can see zeros at regular intervals.
Basically, the stores closed every Sunday.
So, again, this is something you can try to incorporate into your model or we can simply remove these
data points.
As you recall, profit has no problem with missing data because the only regret is time.
This also means that there is no need for your time series to be recorded at regularly spaced intervals
either.
The next step is to call the AFP ducktail just to sanity check.
So, as expected, we see the final dates of our Time series.
OK, so the next step is to rename our columns as profit expects, which is to call the Time series.
Why and the Time Index does.
At this point, our data frame is now ready to pass into profit, but since this lecture has already
been pretty long, we're going to continue this notebook in the next lecture.