WEBVTT

00:01.350 --> 00:06.830
In this video we learn how to use some more advanced filtering techniques service to the mess that's

00:06.840 --> 00:10.610
uh between IS and the to the operator.

00:10.650 --> 00:16.980
So first of all let's import pandas and we are working with our Olympic Games medal status said

00:20.480 --> 00:25.710
And now let's assume that we want to have all medals from these Summer Games in nineteen hundred eighty

00:25.710 --> 00:34.640
eight and so and we can filter our data frame by checking in the column if the value for each row in

00:34.640 --> 00:36.380
the year columnist 1988

00:38.880 --> 00:44.860
and by doing so you'll be creating a really serious and bypassing the boolean serious here to the Logue

00:44.880 --> 00:45.390
operator.

00:45.500 --> 00:51.560
We are creating a brand new data frame with the only rows them that fulfill the condition here.

00:51.570 --> 00:59.120
So let's try it out and star the new data frame and the variable Olympic Games nineteen eighty eight.

01:00.150 --> 01:02.100
And let's check head and tail

01:05.460 --> 01:11.680
so you can see here that we only have medals that were awarded in the year nineteen eighty eight and

01:11.680 --> 01:16.470
so let's check also the info method.

01:16.470 --> 01:20.540
So we have in total one thousand five hundred forty six medals.

01:20.860 --> 01:29.490
And now what if you want to have not only the medals for one year but for example all medals since 1992

01:30.710 --> 01:35.960
so from the addition in 1992 in Barcelona including until today.

01:36.260 --> 01:41.270
And what we could actually do is we could create a boolean serious for each additional so let's say

01:41.630 --> 01:49.670
we create a boolean serious for 1992 then a boolean serious for 1996 with the equals sign and so on

01:49.670 --> 01:57.550
and then we could combine all boolean series with an R operator or what we could do we could simply

01:57.550 --> 02:07.260
use that the Creator equals sign and that we are filtering all rows that the year is 1992 or later so

02:07.260 --> 02:13.140
we don't have to use your many conditions and combine them with an operator we can just use here the

02:13.440 --> 02:20.880
greater or equal sign and let's do this and save the new data frame and the variable Olympic Games since

02:20.880 --> 02:22.080
the 1992

02:24.740 --> 02:29.460
and let's have a look at the first and last throws.

02:29.720 --> 02:35.920
So here we can see we have a data frame starting from 1992 until 2012.

02:35.990 --> 02:41.140
So the dataset ends here in 2012 and the 2016 edition.

02:41.150 --> 02:43.580
So now that a frame.

02:43.620 --> 02:44.040
All right.

02:44.050 --> 02:49.420
So now let's assume that you want to have all medals that were awarded in the 1960s.

02:49.420 --> 02:56.030
So we want to include all games in the 1960s and we can do this.

02:56.100 --> 03:03.890
So the between mass it so we can first of all select the year column and then use that between method

03:03.950 --> 03:10.730
and check if the values in the year series between 1960 and 1969.

03:10.730 --> 03:13.060
So let's check this here.

03:13.490 --> 03:20.130
So we get here a boolean serious and obviously here for the very first rows we get a false because some

03:20.130 --> 03:23.950
of that data frame is starting with eighteen hundred ninety six.

03:24.260 --> 03:31.910
And now again we can pass here our boolean serious to our complete data frame with the local operator

03:32.330 --> 03:33.110
and with the.

03:33.130 --> 03:36.830
Between method that is one additional parameter here.

03:37.220 --> 03:44.000
So this the between method we have to define the left boundary it's 1960 and the right boundary it's

03:44.090 --> 03:50.660
1969 and we have to define if the boundaries are inclusive or exclusive.

03:51.530 --> 03:59.830
So since we want to f all editions in the 60s we pass here through and here we are creating a brand

03:59.830 --> 04:04.040
new data frame and we are storing the data frame and the variable Olympic Games.

04:04.060 --> 04:15.440
60s so let's run the cell and let's have a look at the first rose and the last rose and you can see

04:15.440 --> 04:19.300
here we are starting with the rose where the years are 1960.

04:19.310 --> 04:25.750
So we have here the addition in Rome and we are ending with the 1968 in Mexico.

04:26.390 --> 04:32.240
So and this is actually the good thing with the between method that this works even if I'm not sure

04:32.240 --> 04:35.540
and which yes some Olympic Games took place.

04:35.540 --> 04:40.240
So I do not have to pass a specific year where I know that there was Olympic Summer Games.

04:40.240 --> 04:44.630
So for example in 1964 I simply pass an interval.

04:44.810 --> 04:54.260
So between 1960 and 1969 and I get here the medals for the additions 1960 1964 and 1968.

04:54.330 --> 04:59.130
All right so so far we selected editions that were on a sequential order.

04:59.130 --> 05:06.200
So for example here we selected all games from 1992 until today.

05:06.300 --> 05:12.560
Here we selected all games between 1960 and 1968.

05:12.550 --> 05:18.450
But but if you want to select the Olympic Games that are not sequentially ordered so let's assume that

05:18.450 --> 05:24.390
our favorite games were the additions in 1972 and 1996.

05:24.390 --> 05:30.650
So they are obviously not sequential because they are games between those two for example in nineteen

05:30.850 --> 05:34.470
seventy six or 1992 and

05:37.920 --> 05:43.790
that's create here a list of my favorite games so in 1972 and 1996

05:46.730 --> 05:53.110
and now if you want to filter the data frame we could use two conditions so we feel that for 1972 and

05:53.110 --> 06:00.970
for nineteen ninety six and we combine those two conditions with an R operator all we could use the

06:01.030 --> 06:09.910
s in method so we select first of all the column and then we use in the S1 method and then we pass our

06:09.910 --> 06:18.380
list my favorite games with the two values 1972 and 1996 and then pan as checks for each value in the

06:18.380 --> 06:23.640
year column if the value is either 1972 or 1996.

06:23.650 --> 06:31.180
So let's run near the set and I would expect to get a brilliant serious correct.

06:31.570 --> 06:38.380
And now we can pass here our brilliant series to our summer data frame and the load operator and then

06:38.380 --> 06:48.020
we create a brand new data frame was the medals that were awarded in 1972 or 1996 and we call the data

06:48.020 --> 06:56.610
frame Olympic Games 70 to 96 so let's run here and let's have a look at the first five rows.

06:56.960 --> 07:07.540
And the last five rows so we are starting here with 1972 and ending with the 1996 and let's assume that

07:07.660 --> 07:16.000
we deeply analyze here our data frame and now we want to analyze all other years that are not 1972 or

07:16.000 --> 07:23.830
1996 and we can do this by passing simply here again now append us seriously with all rows with the

07:23.840 --> 07:33.070
1972 on 1996 and then we can use the 2 December which gives us the opposite and then we can pass here

07:33.100 --> 07:39.310
the whole statement to our summer data frame and the log operator and we should get a brand new data

07:39.310 --> 07:48.820
frame with all matters in all year except the additions 1972 and 1996 and we saw the new data frame

07:48.820 --> 07:53.910
and the venerable Olympic summer games not seventy two in 1960.

07:54.040 --> 07:57.060
So let's check this out here.

07:57.370 --> 08:06.180
Let's have a look.

08:06.720 --> 08:13.710
So starting from hundred nineteen six and we can check give us the unique method which uh unique value

08:13.700 --> 08:23.430
is we actually have in our year column so let's check this and we can see that we have all yes except

08:23.640 --> 08:27.980
the years 1972 and 1996.

08:27.990 --> 08:30.740
So our code worked here.

08:30.760 --> 08:35.070
All right so now we are finished with this session and I hope to see you on the next one by.
