WEBVTT

00:01.070 --> 00:06.330
Hi everybody I saw in the last video we learned how to select a single rose with the look operator.

00:06.350 --> 00:12.440
And in this video we will further enhance our skills and learn how to slice the rows and columns service

00:12.440 --> 00:14.240
through the local operator.

00:14.240 --> 00:22.340
But before we start we import pandas and we import our battle data set and set to the indexed column

00:23.020 --> 00:23.840
to athletes.

00:23.870 --> 00:29.320
So athlete is our index column and let's have a look here at the first five rows.

00:29.330 --> 00:37.530
So we have every athlete columnist index and then the last video we learned that was the operator log.

00:37.560 --> 00:41.370
We can make a label based indexing so we can pass a label.

00:41.370 --> 00:48.080
So for example Michael Phelps within this BAP records so let's see what you got here

00:52.020 --> 00:59.960
and we got here a data set to this all rose that contains the Michael Phelps on the index so if the

00:59.960 --> 01:04.800
label yeah of course many times so we get all occurrences of the label here

01:08.190 --> 01:10.940
and same as with the i log operator.

01:10.960 --> 01:15.570
So the first position here within the brackets is for the index.

01:15.570 --> 01:20.130
And the second position here after the commerce for the column.

01:20.130 --> 01:25.310
So what's the first position you index your slice in the index and with the second position.

01:25.500 --> 01:32.410
You slice our index in the column and our flag sample we can select only the column metal

01:37.130 --> 01:45.020
and we get a panda serious with them all occurrences of Michael Phelps s label of our series here and

01:45.030 --> 01:53.380
as the values uh we get all medals off the rose son the name of the panda series will see a medal.

01:53.380 --> 02:03.190
All right so let's copy it here and paste it in our next line and with the local operator we can of

02:03.190 --> 02:06.720
course also slice the for many column.

02:06.720 --> 02:15.490
So for example we want to have a medal and we want to have the event as bracket here is missing.

02:17.230 --> 02:18.790
All right.

02:18.790 --> 02:21.520
So now we get all medals of Michael Phelps.

02:21.560 --> 02:25.300
Um and we get them the kind of medal and the kind of event.

02:25.930 --> 02:26.680
So here.

02:26.680 --> 02:35.280
Michael Phelps won the gold medal for 100 meter butterfly and we can also select for more than one label

02:35.280 --> 02:35.510
here.

02:35.520 --> 02:42.090
So let's copy it here and let's say we're not only want to get all medals and the events of Michael

02:42.090 --> 02:45.480
Phelps but also we are interested in let's say Carl Lewis.

02:46.320 --> 02:51.870
So we open here a list and here we have Michael Phelps.

02:51.870 --> 02:54.770
And uh let's uh try here.

02:54.780 --> 02:55.860
Carl Lewis

03:01.020 --> 03:02.760
and let's close our list

03:05.600 --> 03:08.360
so here we are slicing for Michael Phelps and Carl Lewis.

03:08.390 --> 03:11.050
And we want to know the medals and the event.

03:13.310 --> 03:15.800
And here we get here we have Michael Phelps.

03:15.800 --> 03:19.340
And here we have all occurrences of Carl Lewis.

03:19.820 --> 03:23.750
So he won a gold in 100 meter 200 meter long jump.

03:23.780 --> 03:24.350
And so on

03:29.060 --> 03:34.030
all right so now let's go back and let's have a look at the first 10 rows here.

03:34.030 --> 03:35.150
So we had method

03:39.110 --> 03:44.330
and with the local operator we not only can select four particular rows and columns we can also make

03:44.330 --> 03:45.860
slices.

03:45.890 --> 03:50.280
So for example what if we want to slice from the very beginning.

03:50.420 --> 03:54.580
So from the first draw and two spirit on comes up is slow.

03:54.590 --> 03:55.250
Let's try it.

03:55.280 --> 04:02.480
So we take your summer dot log and then within the back brackets we say OK we want to all rose from

04:02.480 --> 04:04.420
the beginning until.

04:05.330 --> 04:07.220
And let's copy it here.

04:11.840 --> 04:15.280
So let's make clear quotation marks and Let's paste.

04:15.470 --> 04:23.400
So let's see what we got here so we got all the rows from the beginning of flat tires until spirit on

04:23.590 --> 04:24.600
just.

04:24.660 --> 04:32.400
And the very last column here is including So typically with the position based indexing or slicing

04:32.400 --> 04:33.690
like with the i log.

04:33.690 --> 04:40.670
Operator we learned that the starting point is including and the ending point is excluding but now with

04:40.670 --> 04:42.680
them the label base indexing.

04:42.840 --> 04:49.100
So both inside including so we have the starting point including and also the ending point yes be redone

04:49.190 --> 04:54.270
up this is also including and spirit on jazz up.

04:54.270 --> 04:57.690
Is this actually a new unique value in our index.

04:57.690 --> 05:03.990
So there's only one appearance of spirit on Charles up is and let's try to do the same with the flight

05:03.990 --> 05:08.820
sample Michael Phelps we have we know there are many occurrences of Michael Phelps

05:19.970 --> 05:26.780
so now here we can see that we get an error message and it says that cannot get the right Sly's bound

05:26.780 --> 05:28.180
for non unique labels.

05:28.190 --> 05:36.300
Michael Phelps so label based the slicing with the labels that are not unique and does not work here.

05:36.320 --> 05:39.550
All right so and we can also try the following here.

05:39.560 --> 05:40.810
So let's copy it

05:44.720 --> 05:55.190
and um before we saw here that Alfred high US has two occurrences so the first uh row and the first

05:55.190 --> 05:58.330
second third fourth fifth sixth seventh row.

05:58.390 --> 06:05.180
So now if we want to slice and the whole dataset beginning from high retires until the very end.

06:05.210 --> 06:09.390
We can try this so let's copy here the label

06:17.820 --> 06:23.340
so we want to have all rows beginning from us at high us until the very end.

06:23.730 --> 06:30.150
And also here we get an error message cannot get left slice bond fund on unique label Alfred high as

06:31.320 --> 06:35.620
so label based sizing only works with a unique label.

06:35.970 --> 06:42.400
All right so let's move on and let's have a look at uh the twenty first.

06:42.390 --> 06:43.410
The rows here

06:47.450 --> 06:54.080
and what we could do we could actually slice from and uh beginning point to an ending point so let's

06:54.710 --> 07:03.270
take summer download and then we could say we want to slice from Dimitrios to leave us here

07:09.670 --> 07:13.730
until for example Arthur Blake

07:21.030 --> 07:25.020
and I can tell you that both labels are unique and our index.

07:25.410 --> 07:26.580
So this should work.

07:29.270 --> 07:35.100
And then we can see we get a data frame so a slice of our original data frame beginning with Demetrius

07:35.160 --> 07:43.900
Rivas and ending this as a plague and both ending points including and we already know from position

07:43.900 --> 07:50.230
based indexing that by default the starting point is including but the ending points excluding so this

07:50.230 --> 07:58.160
is seer the friend with a label based indexing and we can also do a label based the slicing for the

07:58.160 --> 08:01.580
columns so let's copy it here.

08:05.770 --> 08:12.260
And let's say we want to slice for Demetrius three of us but only for Demetrius three of us and for

08:12.260 --> 08:19.610
the columns we want the columns uh from a year until support including so we could say from the column

08:19.610 --> 08:22.640
year until the columns support

08:27.960 --> 08:34.860
and here we can see that we get for the rows of the label Demetrius three of all columns beginning from

08:34.860 --> 08:36.000
year until spot.

08:36.000 --> 08:42.540
So also here the starting point and the ending point are including all right.

08:42.540 --> 08:45.660
So last but not least let's try another one here.

08:49.520 --> 08:54.280
And uh let's say we want to slice for Michael Phelps again

09:00.140 --> 09:04.730
and we want to slice additionally for let's say Donald Duck

09:10.770 --> 09:13.410
so I do think that there is no label.

09:13.530 --> 09:14.160
Donald Duck.

09:14.160 --> 09:18.630
So there was no athlete that ever won a medal was the named Donald Duck.

09:18.630 --> 09:26.720
But we can check and we can see so first of all we have here all occurrences of Michael Phelps.

09:26.760 --> 09:30.570
And then here at the very end in our new data frame we have them.

09:30.680 --> 09:34.280
They wrote on attack and in our column CMBS and they end badly.

09:34.290 --> 09:40.170
So we have missing values because in our original data frame there is no robust simply labeled on attack.

09:40.170 --> 09:47.820
But still we get here a result but of course with the missing values and piles and drops here a warning

09:49.240 --> 09:56.620
and says that if we pass labels that are actually not in our data frame in the future python will raise

09:56.620 --> 10:00.500
an arrow here and we should use them the re index method.

10:01.240 --> 10:06.910
So but for the time being now we can ignore this because I'm still at that works here.

10:07.000 --> 10:12.250
So we have Donald Duck here with any end values and all the values of Michael Phelps and we know that

10:12.300 --> 10:13.980
penthouse is still under development.

10:13.990 --> 10:18.200
So this could change in the future and therefore we have the future warning.

10:18.210 --> 10:18.670
All right.

10:18.670 --> 10:27.160
So let's copy it here and we can also try to slice four columns which are not in our original data frame

10:27.190 --> 10:28.180
so let's say.

10:28.990 --> 10:29.410
OK.

10:29.410 --> 10:31.110
MICHAEL PHELPS That's OK.

10:34.460 --> 10:37.280
And we want to slice for the columns

10:39.540 --> 10:47.230
here and we assume that now our data frame that's in the column H with the age of each athlete.

10:47.580 --> 10:50.300
So we know that there is no column age but we can try.

10:51.510 --> 10:58.040
And also here we get all occurrences of Michael Phelps here we get the year column and we get the H

10:58.050 --> 11:03.240
column which we do not have from our it's no data frame but here in our new data frame we have the H

11:03.240 --> 11:04.670
column with the missing value.

11:04.690 --> 11:09.830
So it still works and we get to the same future warning that still this works.

11:09.840 --> 11:14.910
So passing labels and that are actually not in the original data frame but in the future which should

11:14.940 --> 11:18.300
use in the re index method.

11:18.490 --> 11:18.840
All right.

11:18.850 --> 11:24.470
So this is it for this session and then next session we will have a quick summary of all that we learned

11:24.480 --> 11:25.630
in the last video.

11:25.640 --> 11:27.310
So to see it there by.
