WEBVTT

00:00.550 --> 00:06.050
We have already learned how to down sample time series data with the read sample method and whenever

00:06.050 --> 00:11.810
we down sample data from higher to lower frequency we have to chain an aggregation method.

00:11.810 --> 00:18.830
So first of all we import pandas and then again we are working with the stocks data set and we select

00:18.890 --> 00:20.370
the close column.

00:20.780 --> 00:26.690
So that's the close or the stocks data frame and apparently here we can see on the left hand side that

00:26.690 --> 00:32.140
we have daily data and let's assume that you want to down sample to annual frequency.

00:32.480 --> 00:40.100
And the question is always how to aggregate all timestamps of a year so never it's we have 252 timestamps

00:40.130 --> 00:41.300
and prices.

00:41.300 --> 00:47.190
So for each trading day and actually we have quite some options how to aggregate them to one price.

00:47.670 --> 00:49.480
So let's have a look here.

00:49.630 --> 00:53.810
And first of all we could take the very first price of each year.

00:54.050 --> 00:56.420
So to say the open price.

00:56.420 --> 01:00.420
So we use the urine sample method on the stocks data frame.

01:00.590 --> 01:07.790
We select annual frequency and as a matter of taste you pass the period to the kind parameter and then

01:07.790 --> 01:08.490
we change here.

01:08.510 --> 01:14.890
The first method so let's have a look at the year 2010.

01:14.890 --> 01:16.700
For Apple we fear the price.

01:16.780 --> 01:18.740
Thirty point five seven.

01:18.970 --> 01:22.110
And this is the very first price in the year.

01:22.110 --> 01:29.920
So on the fourth of January then next we could also take the annual maximum price by changing the max

01:29.920 --> 01:30.490
method

01:34.250 --> 01:43.530
so here for example for the year 2010 the maximum price was forty six point four nine U.S. dollars and

01:43.530 --> 01:51.340
we can also take the annual minimum with the main method and here we are for Apple for example a twenty

01:51.340 --> 01:54.980
seven point forty three in the year 2010.

01:55.090 --> 01:59.040
And finally we can also take the very last price in the year.

01:59.440 --> 02:02.670
So typically it's on the thirty first of December

02:05.980 --> 02:13.250
and obviously here are the very last trading price in 2010 for Apple was forty six point 0 8 so this

02:13.250 --> 02:16.520
for aggregation methods are commonly used in finance.

02:16.730 --> 02:18.640
So let's have a look again here.

02:18.650 --> 02:25.990
We have uh the very first price which is also in the finance industry called the Open price.

02:26.120 --> 02:29.240
Then we have the maximum price soar so high price.

02:29.390 --> 02:32.900
Then we have the minimum price which is the low price.

02:32.960 --> 02:38.650
And finally the last price which is also called to the close price.

02:38.660 --> 02:44.630
So essentially we have you open high low close and finally we can also take the average where you are

02:44.630 --> 02:46.310
with the mean method

02:50.110 --> 02:54.970
so these are essentially four or five commonly used aggregation methods.

02:55.100 --> 03:01.870
And now let's assume that you want to have more than one aggregation in a data frame and we can actually

03:01.870 --> 03:10.750
do this by chaining here the ACT method and then the parent uses that we can pass a list with all aggregation

03:10.750 --> 03:11.690
methods.

03:11.770 --> 03:18.260
So let's assume that we are interested in the open price and the close prices for the year.

03:18.430 --> 03:25.830
Then we can pass here first and last for the method the first and last so let's have a look here.

03:27.660 --> 03:33.300
And here we have actually a multi indexed in the columns and on the outer and next level we have the

03:33.300 --> 03:39.540
stock take us and actually for each and every stock we have uh the first price for the open price and

03:39.540 --> 03:42.360
the last price the close price.

03:42.360 --> 03:49.150
So for example the very first trading price in 2010 for Apple was thirty point five seven.

03:49.260 --> 03:53.430
And over the year had actually moved to forty six point 0 8.

03:53.430 --> 03:57.360
And we can further customize some aggregation with so the act method.

03:57.510 --> 04:04.290
So let's assume that for the Apple stock we are only interested that in open prices for Boeing we are

04:04.290 --> 04:11.280
interested in the closed prices and uh for this we want to have the minimum values and the maximum values

04:11.760 --> 04:18.210
then we can pass the array mapper dictionary to the ACT method and actually as the kicker we need to

04:18.210 --> 04:19.550
pass the column label.

04:19.590 --> 04:27.450
So here the stock take us and s value is the desired aggregation function some methods.

04:27.450 --> 04:28.490
So let's have a look here.

04:31.250 --> 04:38.240
So here we f for APA the first price of the year following the last price and the for this near the

04:38.240 --> 04:40.090
minimum at the maximum price.

04:40.190 --> 04:47.020
And also here we have a multi index in the columns so thanks for watching and I'll see you also in the

04:47.020 --> 04:48.190
next video by.
