WEBVTT

00:00.550 --> 00:04.090
In this video we learn how to remove complete rows from a data frame.

00:04.090 --> 00:11.800
But first of all we import pandas and we import our Summer Olympics data set and reset the athlete column

00:11.800 --> 00:21.210
s so the index and we have a look at the first 10 rows and then let's assume that we want to remove

00:21.300 --> 00:24.570
all instances of Alfred Hi us.

00:24.570 --> 00:30.090
So we have here the estimate column is our index and we have two appearances of three titles and we

00:30.090 --> 00:38.440
want to remove these appearances from our data frame and same with columns we can use and the drop method

00:38.530 --> 00:44.560
and we can now pass to the index parameter the index labels that we want to drop.

00:44.560 --> 00:50.980
So in this case free tiles and we can try to do this.

00:51.740 --> 00:58.580
So here we can see we have dropped off for tiles and let's say again our data frame and it's still there

00:58.580 --> 01:06.350
because we need to set up the in-place perimeter to true but first of all let us decided that we not

01:06.350 --> 01:13.470
only want to remove all instances of life for the tiles but also we want to remove auto Hirschman and

01:13.530 --> 01:19.990
same with columns we can pass a list of labels to the parameter index.

01:20.220 --> 01:25.590
And if you want to change our complete data frame we have to set the in-place parameter to Drew.

01:25.620 --> 01:27.600
So let's do this.

01:28.330 --> 01:31.120
And now let's have a look at our data frame.

01:33.030 --> 01:37.090
So we can see we have to remove TR for tires and auto Ashman

01:40.880 --> 01:43.090
and the same with removing columns.

01:43.100 --> 01:45.880
We have fear for the drop method to alternatives.

01:45.890 --> 01:54.020
So either we can pass our index labels to the parameter index or we can posit to the pyramid does labels

01:54.590 --> 01:56.330
and then we define the axis.

01:56.330 --> 02:05.430
So in this case and the axis is zero or index we can use both either 0 or index in quotation marks and

02:05.430 --> 02:11.190
again if we want to change our data frame we have to set the in-place perimeter to true.

02:11.190 --> 02:12.200
So let's do this

02:15.460 --> 02:23.740
and let's check again if we have now removed the rovers Dimitrios give us yes.

02:23.820 --> 02:25.330
So this works.

02:25.590 --> 02:31.590
So selecting or dropping rows by Row Labels is not something that you will use very often.

02:31.590 --> 02:37.470
So it's more likely to select or drop rows them that meet on do not meet certain conditions and some

02:37.470 --> 02:38.790
columns.

02:38.790 --> 02:43.930
So selecting and removing rows by billion indexing as they are actually the more frequent case.

02:44.310 --> 02:46.080
And let's assume we laughed.

02:46.110 --> 02:49.590
The Summer Olympic Games in 1996 in Atlanta.

02:49.620 --> 02:55.640
And so what we only want to have rows of medals from the 1996 Olympic Games.

02:55.650 --> 03:03.870
And we can do this by selecting all rows that the year column is 1996 and then we can override our summer

03:03.870 --> 03:13.760
data frame and let's see what we get here let's check our new summer data frame and here we have only

03:13.760 --> 03:19.180
rows where we have the value 1996 in the year column.

03:19.190 --> 03:25.160
All right so now let's re import our whole summer Olympics data frame and set the athlete columnist

03:25.160 --> 03:32.440
to the index so now again we have our original data frame.

03:32.490 --> 03:37.500
Now let's assume that we do not want to select a rose that meets certain conditions but we want to drop

03:37.500 --> 03:39.840
rose and that meets certain conditions.

03:39.840 --> 03:46.950
So let's assume we are not interested in the Olympic Games 1996 and we do not like aquatics so we want

03:46.950 --> 03:48.560
to remove all rows there.

03:48.570 --> 03:55.620
The years either 1996 or the sports Aquatics and therefore we create two brilliant serious and then

03:55.620 --> 04:02.970
the first one we check whether the year is 1996 and we assign the variable mask one and then the second

04:02.970 --> 04:10.110
condition we check whether the sport is Aquatics and we assign the variable mask to and then in a first

04:10.110 --> 04:10.410
step.

04:10.410 --> 04:15.840
I filter all rows that meet either condition one or either condition two.

04:15.960 --> 04:23.490
So by having a summer top log and then mask one or mask two I would have all rows where at least one

04:23.490 --> 04:30.700
condition here is Matt however I want to select all rows are neither of the two conditions are met and

04:30.700 --> 04:34.840
therefore I have to use the two the symbol here.

04:34.840 --> 04:41.740
And by doing so I get a data frame with rows where the year is neither 1996 nor the sports columnist

04:41.770 --> 04:49.450
Aquatics and we can override our original data frame and set our new data frame okay.

04:49.460 --> 04:52.790
First of all we have defined our to a mosque one and mosque two.

04:52.820 --> 04:54.000
Okay.

04:54.290 --> 04:56.630
Now this would work and let's have a look here.

04:59.230 --> 05:04.210
So now at a first glance we cannot really see if they're still ninety nine in six and our year column

05:04.240 --> 05:10.830
or aquatics in our spot column and that's actually four ways to do this.

05:10.840 --> 05:16.930
So first of all we check the year column and we create a boolean serious and check whether in the year

05:16.930 --> 05:22.020
column desk nine 1996 and then we make a value account so let's check this.

05:22.600 --> 05:27.490
And you know year column we have actually twenty five thousand three hundred ninety eight forces and

05:27.480 --> 05:36.610
no true so we have removed all instances of ninety nine and six in the year column and we could also

05:36.610 --> 05:43.660
do we could transform our year column into a an umpire Ray this summer to adopt values and check whether

05:43.660 --> 05:51.470
ninety nine in six is in the name pi array and this is false.

05:51.540 --> 05:59.480
All right so we have removed all rows with the ninety nine in six in the year column and let's check

05:59.510 --> 06:04.250
if he's still at the Aquatics and the sports column and we can do this by checking whether in the spot

06:04.250 --> 06:11.050
column there's still Aquatics and we are using the Utzon method so let's try this out here

06:15.070 --> 06:21.670
and we get a boolean serious and now we can check if any of the values in our brilliant serious is a

06:21.670 --> 06:32.220
true and we can do this with the any method and this gives us a false or that's actually no true in

06:32.230 --> 06:37.480
our boolean serious so we have removed all instances of Aquatics

06:40.210 --> 06:45.550
and we can actually do the same and creating the boolean serious by checking whether aquatics is in

06:45.550 --> 06:51.690
the sports column and again we can check whether at least the one true is here in our pavilion serious

06:51.850 --> 06:55.840
with the any method and again we get a false.

06:55.840 --> 07:00.850
So there's no row with aquatics in the sports column.

07:00.990 --> 07:05.650
All right so now this is it for the time being and I hope to see you in the next session by.
