WEBVTT

00:01.710 --> 00:07.460
In this video we learn how to filter data frames based on many conditions so that must all be met.

00:07.470 --> 00:13.530
So first of all we import pandas and we are working with our Titanic data frame.

00:13.740 --> 00:22.040
And here we have the first 10 rows and from the movie we know that after hitting the iceberg there was

00:22.040 --> 00:26.740
a clear code of conduct to first save all women and children.

00:26.870 --> 00:33.830
So women and children had priority for the few lifeboats that were onboard and therefore we can make

00:33.830 --> 00:40.160
the hypothesis that being an adult man was a pretty bad combination for surviving the disaster.

00:40.390 --> 00:47.580
And yeah actually what do you want to do we want to check now if the data supports our hypothesis so

00:47.580 --> 00:51.130
we want to filter all mail that were older than 14 years old.

00:51.150 --> 00:57.970
So you see a 14 years but we could also use 69 in years and actually we have two conditions.

00:58.230 --> 01:06.420
So the passenger must be a male so titanic not sex equals male and we started the boolean serious and

01:06.500 --> 01:13.980
mask one variable and the second condition is that the H must be greater than 14 and we save for the

01:13.980 --> 01:17.610
reciting boolean series in the variable mask too.

01:17.700 --> 01:25.510
So let's check here and we check the first five elements of each mask.

01:25.560 --> 01:31.860
So now we have to combine both conditions with an end operator and only if both conditions are met we

01:31.860 --> 01:33.460
get a true.

01:33.750 --> 01:42.020
So for being an adult male the person must be a male and it must be older than 14 years old so we can

01:42.020 --> 01:48.080
hear use the end sign and combine mask one and Basque two with the end sign and we will have a look

01:48.080 --> 01:50.860
at the first five elements.

01:51.110 --> 01:53.110
So let's go to index Position ZERO.

01:53.120 --> 01:54.670
Here we have true and true.

01:54.700 --> 02:02.390
It's true then in exposition 1 we are false and true gives the false because both conditions must be

02:02.390 --> 02:10.940
met and that in x position 2 we have false and true again and we gather files and so on and now we can

02:10.940 --> 02:19.960
pass mask 1 and mask 2 into our local operator and by doing so we can filter out all the rows we have

02:19.970 --> 02:25.780
we have a male passenger that is older than 14 years old and we can also select here for the columns

02:26.240 --> 02:31.970
so we are only interested in these surveys column in the test was our class column in the sex column

02:31.970 --> 02:40.020
and in the age column so we create here a brand new data frame and we store the data frame in the variable

02:40.050 --> 02:46.940
male survived so let's run the other cell and check the first five rows of our new data frame

02:49.560 --> 02:56.160
and here we have our new data frame we have we have only made that older than 14 years so so we can

02:56.160 --> 02:58.980
also check that say 20 rows

03:04.180 --> 03:08.470
so only male passengers and only made that are older than 14 years old.

03:08.480 --> 03:13.980
So this works here.

03:14.150 --> 03:14.510
All right.

03:14.510 --> 03:19.040
So now we can also get more information on our new data frame with the info method

03:21.690 --> 03:31.840
so we have total 414 passengers that are male and older than 14 years old and let's use the described

03:31.840 --> 03:32.290
method

03:35.190 --> 03:44.810
so we have 414 passengers and we actually know that in the survival column we have 1 4 survived and

03:44.810 --> 03:53.920
the 0 4 not so life and we have a mean year of 0.01 7 in our survival column this means that only 17

03:53.920 --> 04:01.270
percent of all male passengers that were older than 14 years old actually survived the Titanic disaster

04:06.150 --> 04:09.440
and let's recall the survival rate for all passengers.

04:09.450 --> 04:18.060
So let's use the described method on the total data set here and here we can see that on total a thirty

04:18.060 --> 04:25.140
eight point three percent of all passengers survived but in the subset of male passengers older than

04:25.140 --> 04:25.990
14 years old.

04:26.010 --> 04:28.600
Only 17 percent survived.

04:28.860 --> 04:34.320
So it's pretty likely that our hypothesis is true that being an adult male passenger on board of the

04:34.320 --> 04:40.080
Titanic was a pretty bad combination for surviving the disaster.

04:40.110 --> 04:44.910
All right so now we are finished with this session and I hope to see you run next session by.
