WEBVTT

00:01.100 --> 00:07.190
And this video I'm going to show you how to shift all dates of a specific date time index for example

00:07.190 --> 00:13.760
how to add one or more days weeks months or even years to each and every timestamps of the day time

00:13.760 --> 00:14.880
index.

00:14.900 --> 00:22.700
So first of all we import pandas and then let's assume that we have a data frame with a daytime index.

00:22.690 --> 00:29.650
So for example the S&amp;P 500 data frame with historical prices for the S&amp;P 500 index.

00:29.720 --> 00:37.050
But actually we do not care about the prices so we could also have a data frame with orders for a product.

00:37.050 --> 00:40.690
And let's assume latest two calendar days after each and every order.

00:40.790 --> 00:47.000
We have to ship the product and therefore we need to get the shipment data by adding two days to the

00:47.000 --> 00:48.200
order date.

00:48.200 --> 00:49.990
So let's import here.

00:50.330 --> 00:56.990
The data frame and here we have the daytime index starting in nineteen hundred seventy on the thirty

00:56.990 --> 01:02.550
first of December and actually to add two days to each and every time stamp here.

01:02.540 --> 01:08.450
It would be quite intuitive to simply coat here S&amp;P 500 index plus 2.

01:09.260 --> 01:11.860
But of course this doesn't work.

01:11.870 --> 01:15.530
Actually here but there is a solution for it.

01:15.560 --> 01:22.610
And we can actually do this with the direct pen us method that date offset and let's have a look here

01:22.620 --> 01:30.800
inside and here we can define actually a standard kind of date increment used for a date range and TV

01:30.800 --> 01:36.390
and actually define our date increment and uh the default setting is actually one day.

01:36.740 --> 01:41.200
But we can also pass a two to the dates parameter.

01:42.110 --> 01:47.400
So let's run the sale here and if we get a date offset object.

01:47.420 --> 01:52.450
For the time increment of two days.

01:52.680 --> 01:56.940
So again this is a pen does the date offset object.

01:56.940 --> 02:04.430
And first of all let's again get the dates of our original day time index and now we want to shift each

02:04.430 --> 02:07.150
and every time stamp here by two days.

02:07.490 --> 02:13.340
Then we can actually add to our index the date offset object

02:16.630 --> 02:21.210
so we have successfully added Our two days to the thirty first of December.

02:21.220 --> 02:24.070
So here we have the second of January.

02:24.070 --> 02:31.560
Then we shifted to the fourth of January to the sixth of January and so on and actually date offset

02:31.560 --> 02:38.310
method provides so many more options here so we can also determine that we want to have increments of

02:38.430 --> 02:39.600
one week.

02:39.900 --> 02:42.210
So we add to one week.

02:42.210 --> 02:49.470
So for example we shift at the thirty first of December nineteen hundred seventy two the seventh of

02:49.560 --> 02:52.610
January in nineteen hundred seventy one and so on.

02:52.920 --> 02:56.850
And of course we could also pass here two or three add to the week's parameter.

02:56.850 --> 03:05.440
So for example also three weeks and of course you can also have increments of one months or two months

03:05.500 --> 03:06.710
or three months.

03:07.270 --> 03:14.350
So this is no problem here and here we get actually the thirty first of March instead of the thirty

03:14.350 --> 03:19.000
first of December and it also works with a yes.

03:19.090 --> 03:22.780
So we can shift each and every time stamp by ten years.

03:24.200 --> 03:31.580
And instead of having here the thirty first of December nineteen hundred seventy we have the thirty

03:31.580 --> 03:38.210
first of December nineteen hundred eighty and so on and finally we can also combine those increments.

03:38.240 --> 03:44.210
So let's assume that you want to shift to each and every time stamp by one year to month.

03:44.250 --> 03:47.660
Fifteen days the twelve hours and thirty minutes.

03:47.690 --> 03:49.010
Then we can do this here

03:51.600 --> 03:59.740
so here we have the 15th of March nineteen hundred seventy two at twelve thirty.

04:00.150 --> 04:04.920
And so far we added a specific period to each and every time stamp.

04:05.100 --> 04:10.940
But we can also say abstract to a period and go back to the past.

04:10.950 --> 04:17.790
So for example we can go back one day by having a minus sign instead of a plus sign.

04:17.790 --> 04:24.020
So this also works and instead of having you know the thirty first of December nineteen hundred seventy

04:24.450 --> 04:32.500
we have here the 30th of December so that was the first video on shifting dates and I hope to see you

04:32.500 --> 04:34.180
also in the next one by.
