WEBVTT

00:01.210 --> 00:06.740
In the last couple of videos we have learned how to transform a sequence for example a panda series

00:07.220 --> 00:13.410
or a list containing strings with the date time information into a date time index.

00:13.430 --> 00:20.030
So let's import pandas and let's assume that here we have a list with two strings.

00:20.030 --> 00:28.610
So the 20th of May to 15 and the 20th of February to 15 and we can pass here the list to the pandas

00:28.610 --> 00:36.850
method to date time and by doing so we are getting here a day time index with two timestamps.

00:37.020 --> 00:41.920
Now let's assume that we want to create a daytime index service many time stamps.

00:41.930 --> 00:49.760
So for example if we want to f all 31 days in July to 15 so creating and passing all 31 strings to the

00:49.810 --> 00:54.090
two day time method many earlier is actually not really efficient.

00:54.230 --> 01:00.140
And if we have constant frequency so constant increments between the time stamps then we can simply

01:00.140 --> 01:09.140
do this limit the direct Panda's method date range and in our example so all days in July to and fulfills

01:09.150 --> 01:10.370
them the condition.

01:10.460 --> 01:15.480
So we have here a daily frequency or increments of one day.

01:15.800 --> 01:21.460
So let's use here the direct pandas method date range and let's have a look here.

01:23.080 --> 01:29.750
So we have here the stop parameter and two we can pass the string with the date that we want to have

01:29.780 --> 01:30.930
a start.

01:30.940 --> 01:38.260
So here are the first of July and we have also the repair meter end and here we pass the thirty first

01:38.260 --> 01:38.980
off July.

01:39.370 --> 01:43.150
And then there's the additional parameter freq for frequency.

01:43.150 --> 01:45.610
And let's have a look here and here.

01:45.610 --> 01:48.130
The default setting is capital D.

01:48.160 --> 01:49.850
So this stands for days.

01:49.960 --> 01:53.670
So we can also explicitly set the frequency power meter.

01:53.670 --> 02:03.500
Two days this is just here for clarification and by doing so we're actually creating all days starting

02:03.500 --> 02:07.850
from the 1st of July onto the thirty first of July.

02:07.880 --> 02:15.310
So let's do this here and here again see we get to the first or the second the third onto the thirty

02:15.310 --> 02:16.190
first.

02:16.420 --> 02:24.130
And this is set a day time index with uh thirty one time stamps and the data types the date time 64

02:24.130 --> 02:31.600
data type and we have a frequency of D or so daily frequency and let's again have a look here at the

02:31.600 --> 02:34.110
documentation and that the pair meet us.

02:34.480 --> 02:38.200
So essentially we have three parameters we have the stock power meter.

02:38.410 --> 02:42.190
We have for the Empire meter and we have the periods power meter.

02:42.670 --> 02:49.700
And actually we have to define two out of these three parameters to call our date range method.

02:49.720 --> 02:58.180
And of course we have also to define the frequency so instead of passing the first two stop and the

02:58.210 --> 03:05.800
30 first to end B can also pass here the first to start and we can say we want to f thirty one periods

03:06.430 --> 03:09.040
and we want to have a daily frequency.

03:09.520 --> 03:17.500
And by doing so we are getting actually the same identical daytime index from the 1st of July onto the

03:17.530 --> 03:21.990
thirty first of July and s also a third alternative.

03:22.000 --> 03:29.770
So we could alternatively set here the end power meter and the periods pair meter so the end date is

03:29.820 --> 03:34.630
uh the thirty first of July and you want to f 31 periods.

03:34.900 --> 03:37.000
And again the frequency is daily.

03:38.680 --> 03:46.560
And also here we get the same identical daytime index so again we have three paramedics we have stop

03:46.650 --> 03:55.140
and and periods and we have to set are determined to out of these three parameters and additionally

03:55.140 --> 03:58.850
the frequency parameter and for the frequency parameter.

03:58.860 --> 04:06.750
We have many different options so feel free to have a look at the documentation to see all options and

04:06.750 --> 04:10.830
one option is to pass a B for business day.

04:10.860 --> 04:18.350
So again we have here the first of July a start and the thirty first up to my ass end and the U.S.A

04:18.390 --> 04:19.350
business days

04:22.660 --> 04:28.180
and we get the first the second the third and the sixth of July.

04:28.260 --> 04:33.810
So we do not have the fourth and the fifth because of this Saturday and Sunday.

04:34.260 --> 04:40.560
So Saturday and Sunday are not business days and therefore here in this day time index we have only

04:40.560 --> 04:43.580
business days or actually weekdays.

04:43.650 --> 04:46.460
So from Monday to Friday.

04:46.470 --> 04:46.890
All right.

04:46.890 --> 04:51.080
Now let's assume that our start date is the thirty first of July.

04:51.450 --> 04:59.490
And you want to have 10 timestamps with hourly frequency so we pass your h for hourly frequency

05:03.900 --> 05:09.190
and by default we are starting here at midnight on the thirty first of July.

05:09.690 --> 05:16.620
And then we have four year increments of one hour or so we have 1:00 2:00 3:00 until 9:00.

05:16.620 --> 05:22.980
So in total 10 timestamps because they pass the 10 to the parameter periods.

05:22.980 --> 05:31.960
So we have a daytime index that's 10 times stamps and the frequency is h for hourly.

05:32.050 --> 05:34.750
All right and we can also have a weekly frequency.

05:35.200 --> 05:38.380
So yeah our start date as the first of July.

05:38.800 --> 05:45.970
And we want to have six periods and you want to have weekly frequency so we pass yet w to the frequency

05:46.000 --> 05:46.720
parameter

05:49.430 --> 05:53.410
and now at a very first glance this looks quite strange.

05:53.420 --> 06:00.710
So our very first timestamp as of the 5th of July and not to the first of July and this is because by

06:00.710 --> 06:07.460
default if you pass your weekly clear then we get here only some days and actually penned us checks

06:07.460 --> 06:12.700
here from the Stop day bad the very first Sunday is and the very first Sunday is on the 5th.

06:13.400 --> 06:16.760
So here the 5th is our first time stamp.

06:16.750 --> 06:24.020
Then we have our second time stamp at the tomatoes and so on and the very last time stamp and the sixth

06:24.020 --> 06:27.680
time stamp is the 9th of August.

06:27.710 --> 06:35.780
So here we have a daytime index with six some days and we can see this here at the frequency we have

06:35.800 --> 06:43.300
here weekly Sunday and now let's assume that you want to have a starting from the 1st of July it only

06:43.300 --> 06:43.900
Wednesday.

06:43.930 --> 06:52.210
So we want to have the next six best days and we can do this by not passing the weekly but we clear

06:52.390 --> 06:53.870
then minus or dash.

06:53.920 --> 06:55.150
And then Wednesday

06:58.580 --> 07:01.850
and apparently the 1st of July is a Wednesday.

07:02.180 --> 07:04.970
So pandas starts from here.

07:04.970 --> 07:11.430
The starting point and then searches for the very first the Wednesday here in this case it is the 1st

07:11.450 --> 07:12.260
of July.

07:12.500 --> 07:17.690
And then here in total we have the next six Wednesdays from the 1st of July here.

07:17.900 --> 07:21.060
And actually we can create you all week day so we can pass here.

07:21.080 --> 07:27.890
If our AI for Friday are we weekend pass Tuesday and so on and here and the frequency we can see here

07:27.890 --> 07:28.360
that.

07:28.370 --> 07:30.650
Here we have Wednesdays.

07:30.650 --> 07:35.760
All right so now let's go to monthly frequency and for monthly we can pass here.

07:35.770 --> 07:42.590
M So our starting day is the 14th of July and we want to have six timestamps.

07:42.590 --> 07:45.730
So let's try this out here.

07:46.100 --> 07:52.340
And by default when we are passing the M to the frequency parameter we are getting it actually the month

07:52.430 --> 07:53.550
and dates.

07:53.600 --> 07:57.300
So pen that starts here at the 14th of July.

07:57.710 --> 08:04.520
And searches are the very first month and the date and this is the thirty first of July.

08:05.240 --> 08:10.420
And then we have the next consecutive five month ends.

08:11.000 --> 08:16.220
So we have for the thirty first of August the 30th of September and so on.

08:16.970 --> 08:22.790
And let's assume that instead of having the month and we want to for the very first day of each month

08:23.240 --> 08:28.410
and we can do this by passing here m s so far start.

08:28.640 --> 08:36.790
So we get the start of each month and again your partner starts here at the starting point and searches

08:36.790 --> 08:39.870
for the very first uh beginning of months.

08:39.880 --> 08:47.800
And this is here the first of August and then we FBA the first of September and so on and here we can

08:47.800 --> 08:51.350
see the frequency as the month start.

08:51.370 --> 08:51.880
All right.

08:51.880 --> 09:00.490
Now let's assume that we want to have the 14th of July August September October November and December.

09:00.490 --> 09:04.340
So we want to have six period starting from the 14th of July.

09:04.630 --> 09:12.130
And instead of passing your monthly or month start we can pass here a special pants method called Date

09:12.220 --> 09:19.870
offset and tier but then the brackets have to define that the frequency should be month slow the frequency

09:19.870 --> 09:20.850
is one month.

09:21.400 --> 09:23.530
So let's try this out here.

09:23.650 --> 09:31.680
And by doing so we're creating the timestamps 14th of July 14th of August and so on and we can see in

09:31.690 --> 09:37.240
the frequency that we have a date offset of month equals 1.

09:37.240 --> 09:40.650
All right so now let's head to quarterly frequency.

09:40.930 --> 09:44.460
And again our starting point this the 14th of July.

09:45.070 --> 09:48.850
And we want to have a quarterly frequency for six periods.

09:50.800 --> 09:58.300
And if we get us a very first time step the Saudis offer September and typically a quarter is defined

09:58.330 --> 10:01.060
as the first quarter from January to March.

10:01.420 --> 10:08.500
Then the second quarter from April to June then the third quarter from July to September and the fourth

10:08.500 --> 10:11.110
quarter from October to December.

10:11.500 --> 10:17.500
And by default if you pass me a cure then we get to the end date of the quarter.

10:17.500 --> 10:26.000
So the next end date of a quarter is here starting from the 14th of July the 30th of September.

10:26.350 --> 10:30.580
So this is the very last day of the third quarter.

10:30.580 --> 10:38.140
And then the next time stems that consequently the thirty first of December to 15 and then the thirty

10:38.140 --> 10:44.390
first of March to 16 and so on and we can also see this year and the frequency.

10:44.650 --> 10:48.080
So if we pass cure then by default we are getting here.

10:48.090 --> 10:57.040
Q December so that means that the last month of the fourth quarter is December and bypassing here.

10:57.040 --> 11:03.200
Q S instead of Q We are getting actually the very first day off a quarter.

11:03.250 --> 11:11.820
So let's do this here and starting from the 14th of July the very first day of the next quarter is in

11:11.850 --> 11:13.670
the first of October.

11:13.740 --> 11:18.030
Then we get the first of January to 16 and so on.

11:18.030 --> 11:25.920
And in this case the frequency is called Q S January and now let's assume that we want to have quarters

11:26.010 --> 11:30.900
different from January to March April to June and so on.

11:30.900 --> 11:39.480
So let's assume for example that we want to have quarters from May to August and from September to November

11:40.050 --> 11:42.530
and we can do this by passing your flight sample.

11:42.540 --> 11:49.260
Q May and by default we are getting at the very last day of each quarter.

11:49.590 --> 11:56.700
So starting from the 14th of July the next last day of the quarter is the thirty first of August and

11:56.700 --> 11:57.310
so on.

11:57.900 --> 12:02.550
And also instead of getting the last day of each quarter we can get to the first day of each quarter

12:02.550 --> 12:10.860
by passing q s main and we should get then the first of August s first time.

12:11.420 --> 12:13.950
And this is true.

12:14.060 --> 12:22.570
All right now let's go to any other frequency and we are starting here also with the 14th of July.

12:22.670 --> 12:29.600
We want to have six periods and a annual frequency so we can pass here a while we can also pass your

12:29.600 --> 12:30.070
base.

12:30.080 --> 12:31.640
So this is the same

12:34.340 --> 12:39.140
and by default we are getting near the very last day of the calendar year.

12:39.200 --> 12:45.370
So here are the thirty first of December so we are getting here the thirty first of December off to

12:45.370 --> 12:49.150
15 16 17 18 19 and 20.

12:49.360 --> 12:57.340
And the frequency is called annually December and alternative we can also get the very first day of

12:57.370 --> 12:58.350
a calendar year.

12:58.360 --> 13:01.150
So the 1st of January.

13:01.420 --> 13:03.910
And therefore we have to pass a s

13:06.940 --> 13:09.130
and starting from the 14th of July.

13:09.160 --> 13:15.230
So the very first time stem is the first of January to a 16.

13:15.370 --> 13:18.440
And here we can see the frequency as a s.

13:18.500 --> 13:26.060
January All right now let's assume that we want to have annual data but instead of having a year from

13:26.060 --> 13:31.420
January to December we want to f a year from July to June.

13:32.000 --> 13:35.420
And therefore we can pass here a June

13:39.270 --> 13:41.070
A.B. get by default.

13:41.100 --> 13:47.420
The very last day of our year and the very last day is here the 30th of June.

13:47.880 --> 13:53.830
And starting from the 14th of July to 15 our first time stamp is now in 216.

13:53.880 --> 14:02.220
And of course we can also get the very first day of each year by passing year A S June.

14:02.300 --> 14:08.510
And if you want to have the year from July 2 to 1 with the very first day of the year then we have to

14:08.510 --> 14:09.920
pass you a s.

14:09.950 --> 14:10.570
July.

14:11.210 --> 14:13.550
So this should work.

14:13.550 --> 14:16.330
So now we have the 1st of July.

14:16.670 --> 14:24.410
And last but not least we can also create a yearly timestamps for example for the 24th of November.

14:24.440 --> 14:26.010
So this is my birthday.

14:26.270 --> 14:31.610
And let's assume I want to f the time stamps for the last 10 birthdays.

14:31.610 --> 14:37.640
So the last birthday was on the 24th of November to 18 and periods is 10.

14:37.970 --> 14:44.550
And here again I can pass the special method BD Date date offset to the frequency prior meter.

14:44.960 --> 14:50.770
And you're within the brackets like I can pass the frequency of one year.

14:50.930 --> 14:57.990
So let's try this out until we get to the day time index with the last 10 best days.

14:58.130 --> 15:07.310
So starting from the 24th of November 2009 to the 24th of November 2018.

15:07.360 --> 15:07.820
All right.

15:07.820 --> 15:14.270
This was a very detailed look on the date range method and are actually plenty of combinations that

15:14.270 --> 15:15.170
we can use here.

15:15.170 --> 15:19.530
So the date range method is quite powerful and useful.

15:19.880 --> 15:25.640
And in practice there's hardly any case that we cannot come up with the date range method.

15:25.640 --> 15:31.460
So this is very useful and with this we are finished with this video and I hope to see you also in the

15:31.460 --> 15:32.570
next one by.
