WEBVTT

00:00.770 --> 00:03.830
This video is an introduction on the time that object.

00:03.980 --> 00:08.380
So let's assume that you want to determine the time difference between two time stamps.

00:08.390 --> 00:11.710
Then we can do this by creating a time Delta object.

00:11.840 --> 00:17.520
So first of all we import pandas and then we create two time stamps.

00:17.540 --> 00:25.040
So we have for the 15th of August 215 and the 2nd of September to 15 and actually we save the two time

00:25.040 --> 00:27.920
stamps and the variables August and September

00:30.800 --> 00:36.580
and let's assume that you want to determine the time difference between those two time stamps.

00:36.680 --> 00:42.610
Then we can simply do this by having September minus August so we can essentially you'll see the minus

00:42.620 --> 00:46.160
operate on two time stamps and actually be safe.

00:46.160 --> 00:50.450
They reside in the rabbit data and here we have data.

00:50.480 --> 00:52.790
So this is a time that object.

00:52.810 --> 00:54.380
And the SS 18 days.

00:54.380 --> 01:01.050
So there is a time difference of 18 days and we can also check the data type and let's say pandas the

01:01.050 --> 01:07.480
time that are checked and then we can also at a time that object to a timestamp.

01:07.530 --> 01:14.260
So we have our timestamp uh the 15th of August and we can add uh 18 days.

01:16.120 --> 01:23.200
And we get actually a timestamp so it's of course the 2nd of September to 15 and we can also subtract

01:23.230 --> 01:26.070
a time that object from a timestamp.

01:26.110 --> 01:28.860
So we have fear September minus data.

01:29.860 --> 01:37.000
And of course we get here the 15th of August to 15 and we can also exchange August and September so

01:37.000 --> 01:45.800
we can f August to minus September and if we get a negative the time that object so it's minus 18 days.

01:45.820 --> 01:48.820
So this is one way to create a time to add objects.

01:49.000 --> 01:56.800
So we substructure the one time stamp from another but we can also create a time that objects from scratch

01:57.220 --> 02:05.250
with the direct pen us method two time data and let's have a look here inside the parent uses so the

02:05.250 --> 02:12.210
two time that the method converts an argument to a time data and we actually have to pass an argument

02:12.810 --> 02:15.290
and we have actually many options here.

02:15.720 --> 02:19.830
So we can pass the days hours minutes and seconds.

02:20.280 --> 02:28.290
So for example we could pass here one day and actually we need to have it as a string and here we have

02:28.380 --> 02:29.980
the time that object.

02:30.000 --> 02:36.790
One day and that's actually quite flexible here so we can also have um capital letters.

02:36.790 --> 02:38.880
So this also works.

02:38.970 --> 02:46.720
Of course it must be a capital D not a capital S so this works and actually doesn't matter if we for

02:46.720 --> 02:48.320
one day or one days.

02:48.940 --> 02:50.740
So this also works here.

02:51.060 --> 02:53.340
And also it's a lowercase S..

02:53.620 --> 02:56.830
So we are completely flexible here.

02:57.280 --> 03:01.890
And of course we can also create a time that object with many days so we can pass the 10 days.

03:01.890 --> 03:03.340
One hundred days.

03:03.380 --> 03:06.040
Five thousand three hundred days.

03:06.460 --> 03:08.490
So that's no problem.

03:08.560 --> 03:15.700
And we can also create time that objects with hours so we can for example having time increment of two

03:15.700 --> 03:16.930
hours.

03:17.680 --> 03:19.750
Or we can f five minutes.

03:19.750 --> 03:25.190
So here we have two hours or zero days and two hours and we can also create five minutes.

03:25.210 --> 03:32.580
So here we have uh three days zero hours and five minutes and we can also create seconds for example

03:32.590 --> 03:39.890
twenty nine seconds so there are days zero hours zero minutes and twenty nine seconds.

03:39.930 --> 03:43.980
And of course we can also have a combination of days hours minutes and seconds.

03:43.980 --> 03:48.980
So for example ten days two hours five minutes and 30 seconds.

03:49.980 --> 03:53.070
And finally instead of days we can also have 10 days.

03:53.100 --> 03:55.700
So this also gives us 10 days.

03:55.830 --> 03:59.490
And that's also an option to create a time that object with.

03:59.550 --> 04:00.530
Yes.

04:00.570 --> 04:09.580
So for example one year with a Y and this gives us actually an exact year so three hundred sixty five

04:09.580 --> 04:15.730
days and almost six hours and we can also create weeks with W.

04:16.180 --> 04:18.640
So one week is actually seven days.

04:19.420 --> 04:22.110
However there's one thing that we cannot do.

04:22.210 --> 04:27.930
So there's no multiple of month because there there's no exact the duration of a months.

04:27.940 --> 04:34.050
So we have months with 30 days or 31 days or even 28 or 29 days.

04:34.300 --> 04:39.420
And therefore by passing one M we get actually one minute.

04:39.730 --> 04:46.930
So you have one minute and let's also work with a data set where we have a timestamp for daytime index

04:47.410 --> 04:50.860
for example the S&amp;P 500 data set.

04:50.930 --> 04:54.760
So that's the data frame with a daytime index on the left hand side.

04:54.940 --> 05:00.430
And then we've already learned that we can create for each and every timestamp the next quarter and

05:00.430 --> 05:05.280
date and even more particular the next quarter and the business day.

05:05.500 --> 05:13.270
And we can do this with PD time series offsets and business quarter end and we can actually at this

05:13.270 --> 05:22.030
time offset object to to the index here and by doing so we are actually creating a new column with business

05:22.150 --> 05:23.220
quarter end dates.

05:23.220 --> 05:29.770
So let's simply run the sale here and here we have actually for each and every timestamp the next business

05:29.770 --> 05:30.790
quarter and day.

05:31.330 --> 05:35.640
So for example for the thirty first of December nineteen hundred seventy.

05:35.800 --> 05:42.820
The next the business quarter and day is um the thirty first of March nineteen hundred seventy one.

05:42.820 --> 05:49.480
So we FBA the index with daytime information and we have another column with the daytime information

05:50.230 --> 05:53.760
and then we can actually create the difference between the index or the column.

05:53.900 --> 06:00.310
Or we could also create the difference between the two columns that contain daytime information and

06:00.310 --> 06:05.260
we can actually simply do this by having here the column minus the index.

06:05.480 --> 06:07.910
And by doing so we are creating a new column time.

06:07.910 --> 06:10.930
There are lots of luck here.

06:10.930 --> 06:17.890
So you have the new column time data and you will have the time difference between the column business

06:17.890 --> 06:21.060
quarter and day and the daytime index.

06:21.280 --> 06:22.680
And it's actually in days here.

06:22.690 --> 06:26.130
So we have 90 days 86 days and so on.

06:26.350 --> 06:30.350
And let's also get some meta information here with the info method.

06:30.490 --> 06:34.150
So here we can see that we have fun column with the date time information.

06:34.150 --> 06:40.720
Then we have a daytime index and actually the column time that contains the time that our objects and

06:40.720 --> 06:45.420
we can also determine that the column time that should be the index of our data frame.

06:45.420 --> 06:53.740
So first of all we reset the index and then we've set the column time that us being the index.

06:53.890 --> 06:59.570
So here we have on the left hand side to the time that the index and it's uh essentially a time tell

06:59.570 --> 07:00.280
the index.

07:00.280 --> 07:08.030
So here we can see this and finally by subtracting the time data index from the column business quarter

07:08.060 --> 07:16.070
and day then we should again get the original date column so we can check this with the equals method

07:17.540 --> 07:19.670
and that's true here.

07:19.670 --> 07:20.030
All right.

07:20.030 --> 07:22.780
This was a short introduction on the time that object.

07:23.150 --> 07:26.480
So thanks for watching and I see you also on the next video by.
