WEBVTT

00:01.730 --> 00:07.580
In this video we will quote some more examples love split apply combine and by doing so you want to

00:07.580 --> 00:13.230
get more insight into our data and we want to find more interesting facts and relationships.

00:13.250 --> 00:18.810
All right so now let's first of all import pandas and now we are working with the Summer Olympics data

00:18.870 --> 00:19.250
said

00:24.230 --> 00:30.080
and now we want to find the 20 most successful countries in the history of Summer Olympic Games with

00:30.140 --> 00:34.100
the highest number of medals and therefore we have to split here.

00:34.100 --> 00:40.910
Our summer data frame by the column or by the key country and by doing so we are getting about 140 40

00:41.060 --> 00:48.020
different groups our countries and for each group we want to count the amount of medals that were already

00:48.020 --> 00:50.810
awarded to athletes from the country.

00:51.410 --> 00:57.740
And therefore we are only interested in the medal column and for each group we want to count the amount

00:57.740 --> 01:05.870
of non values in the medal column and we can do this with the count method and we are starting the results

01:05.900 --> 01:10.940
in the variable medals per country so let's do this and also print medals per country.

01:12.200 --> 01:18.800
And we can see here on the left side we have the country and on the right side the total amount of medals

01:18.920 --> 01:22.550
that were awarded to athletes from the respective country.

01:22.880 --> 01:31.130
So for example Afghanistan has two medals then here Belgium has four hundred and eleven medals.

01:31.130 --> 01:35.290
And Brazil has 400 31 medals and so on.

01:35.420 --> 01:41.100
And what we actually wanted to know is actually the 20 most successful countries.

01:41.150 --> 01:46.130
So what we can do now actually we can change the year the method and just

01:50.170 --> 01:53.430
and we want to have the 20 countries with the most medals.

01:53.440 --> 01:56.230
So let's pass here and equals 20.

01:57.310 --> 02:00.590
And by running the side we are actually overriding the rebels.

02:00.610 --> 02:01.480
So let's do this

02:05.480 --> 02:08.540
A.B. After the 20 most successful countries.

02:08.540 --> 02:15.410
So no surprise that the most successful country is the USA and the second most successful country I

02:15.410 --> 02:18.340
think this is the former Soviet Union.

02:18.350 --> 02:27.050
And then we have great Britain France Germany Italy Australia Hungary Sweden other lands and so on so

02:27.050 --> 02:35.400
actually on ranked 20 is Denmark with five hundred and seven medals and we can also plot our results

02:35.410 --> 02:37.110
yet in a bar chart.

02:37.190 --> 02:40.550
So let's first of all import plot lib as always.

02:40.550 --> 02:42.320
And we use in the seaborne stated

02:45.280 --> 02:48.730
and then we are plotting here our pandas serious matters per country.

02:48.750 --> 02:57.430
And we are using a bar chart and the figure size is 14 aid and we are using a font size of 14 and we

02:57.430 --> 03:03.880
f at the X label of country the violator the number of medals and the titles the Summer Olympic Games

03:03.910 --> 03:05.200
total medals per country.

03:05.200 --> 03:06.820
So let's see what we get here

03:11.180 --> 03:17.230
and here we have the bar chart of the 20 most successful countries in some Olympic Games.

03:17.230 --> 03:24.640
So number one this year USA was over 4000 medals then we have the former Soviet Union Great Britain

03:24.640 --> 03:28.270
France and to Poland and Denmark.

03:28.270 --> 03:28.740
All right.

03:28.750 --> 03:31.780
So now let's head over to our Titanic data dataset

03:36.040 --> 03:43.090
and we can use here to describe method to get some more summary statistics on our North America columns

03:46.080 --> 03:54.890
so here we can see for example that the average fare that OP hasn't just paid was uh 30 to and we can

03:54.890 --> 03:57.890
also apply the mean method directly on the fare column.

03:57.890 --> 04:01.710
So also give you should get thirty two point two.

04:02.060 --> 04:05.560
And this is actually the average fare for all passengers.

04:05.570 --> 04:12.020
But now let's assume that we want to know the average fare for all passenger classes and we can do this

04:12.500 --> 04:16.160
by splitting our data frame into the passenger classes.

04:16.160 --> 04:22.760
So we have three passenger classes then we only select select the fare column and we want to know the

04:22.760 --> 04:26.840
average are the mean fare paid by the three passenger classes.

04:26.840 --> 04:28.070
So let's do this here.

04:29.000 --> 04:34.190
And it's actually no surprise then that the average fare for the first class is highest.

04:34.190 --> 04:42.170
So 84 than the average fare paid by a second class passengers is twenty point six and third class passengers

04:42.170 --> 04:45.800
paid on average thirteen point six.

04:45.800 --> 04:53.270
And we can also take the sum over the whole survival column so we might recall that in these last column

04:53.300 --> 04:57.510
we have one fossilized and 0 4 not survived.

04:57.860 --> 05:03.540
And by taking the sum over these survived column we should get the total amount of passengers who actually

05:03.540 --> 05:05.590
is left to disaster.

05:05.600 --> 05:07.480
So let's do this.

05:07.520 --> 05:10.940
So in total a three hundred forty two passengers survived.

05:11.570 --> 05:18.540
And by calculating the mean on the survive column we are actually calculating the survival rate.

05:18.830 --> 05:25.160
So one stands for survived 0 4 not survived and by taking the mean we are actually getting these survival

05:25.160 --> 05:25.520
rate

05:28.300 --> 05:33.410
so only thirty eight point three of our peasant system survived the disaster.

05:33.410 --> 05:37.360
And we know that there was a clear code of conduct and filling the lifeboats.

05:37.370 --> 05:39.740
So women and children first.

05:39.830 --> 05:45.920
And now we can check if they really followed the code of conduct and we can do so by calculating the

05:45.920 --> 05:51.290
survival rate for different groups of flight sample we can calculate the survival rate for them and

05:51.290 --> 05:55.910
for man for children for adults and also for passenger classes.

05:55.910 --> 06:02.900
And as a first step let's calculate the survival rate by gender so the survival rate of all few male

06:02.900 --> 06:04.760
passengers and on male passengers

06:07.580 --> 06:10.730
and we can see that there is a significant difference.

06:11.000 --> 06:18.980
So the total survival rate of all passengers was 38 percent but the survival rate for the female passengers

06:19.040 --> 06:25.250
were 74 percent and for all male passengers only 18 or 19 percent.

06:25.310 --> 06:29.060
And we can also check the survival rate by passenger class

06:33.420 --> 06:39.990
and we can see that first and second class passengers had some priority when it comes to getting a place

06:40.020 --> 06:41.700
in a lifeboat.

06:41.700 --> 06:48.840
So sixty three percent of all first class passengers survived and only 24 percent of all third class

06:48.840 --> 06:49.920
passengers survived.

06:49.950 --> 06:51.660
So this is a clear difference.

06:51.870 --> 06:56.030
And we can also split our data frame into adulthood and children.

06:56.070 --> 07:02.340
However we do not have a column with added ought to run and therefore we have to create a new column.

07:02.430 --> 07:05.060
So we create the column adult to run.

07:05.610 --> 07:13.170
And first of all we assign the value added to all rows and then we filter our data frame and for all

07:13.170 --> 07:20.400
rows we add the h just below 18 B overwrite the value in the edited to add one column by adding value

07:20.400 --> 07:21.120
would tie it.

07:21.120 --> 07:27.440
So let's do this here and let's have a look at our data frame with our new column.

07:27.450 --> 07:28.380
Add a child

07:31.110 --> 07:37.320
so we can see here for the first 5 percent just about are all older than 18 years old and therefore

07:37.350 --> 07:39.470
we have here the value added.

07:39.660 --> 07:42.870
But let's have a look at some more rows here

07:46.530 --> 07:51.840
so here the peasant at next position 7 is actually only two years old.

07:51.990 --> 07:54.920
And here we have the value child and the column.

07:54.930 --> 07:55.710
Adult child

07:58.460 --> 08:05.460
all right and let's also now analyze our adult child to the column by counting the values with the method

08:05.460 --> 08:14.060
to value counts so in total we have seven hundred seventy eight adults and one hundred thirteen children.

08:14.230 --> 08:21.570
And we can also split and group our Titanic data frame by the column add a child and we can calculated

08:21.610 --> 08:24.580
the survival rate for adults and for children.

08:24.600 --> 08:25.510
So let's do this

08:29.100 --> 08:37.410
so on average uh 36 percent of all adults survived and about 54 percent of our children survived the

08:37.410 --> 08:38.510
disaster.

08:38.790 --> 08:44.430
And we've already learned that we can use more than one key so we can use two or three or even more

08:44.430 --> 08:46.780
keys to split our data frame.

08:47.010 --> 08:51.960
And now as and the Code of Conduct was uh women and children first.

08:52.290 --> 09:00.000
We want to split our data framed by the sex and by the adult or child column and by doing so we can

09:00.000 --> 09:03.000
split our data frame into four groups.

09:03.240 --> 09:05.960
And you want to analyze this advice column.

09:05.970 --> 09:09.870
But first of all do you want to count the number of peasants us in each group.

09:09.870 --> 09:17.700
So let's do this here with the count method so here we can see we have four different groups.

09:17.920 --> 09:20.680
So we have the combination of female and adult.

09:20.680 --> 09:27.180
We have the combination female child and we have the combination male adult and a male child.

09:27.190 --> 09:33.640
So here we have actually a minority index or hierarchical index where the first index columnist and

09:33.640 --> 09:39.540
the sex column and the second the other child column and here on the right side we have the values.

09:39.610 --> 09:42.450
So the amount of passengers in each group.

09:42.580 --> 09:49.120
So we have here a panda serious with a hierarchical index and we want to calculate the survival rate

09:49.120 --> 09:58.290
for all four groups and instead of applying the count method we now can apply the mean method and what

09:58.290 --> 10:04.890
we can already do we can slot our four groups from the highest survival rate to the lowest survival

10:04.890 --> 10:10.770
rate with the sort values method and passing falls to the ascending parameter

10:14.050 --> 10:20.170
so we have a descending order starting with the group with the highest survival rate until the group

10:20.170 --> 10:21.850
has the lowest survival rate.

10:21.850 --> 10:29.590
So let's do this here and here we can see the group with the highest survival rate is actually female

10:29.590 --> 10:32.830
adults with 75 percent survival rate.

10:33.160 --> 10:39.290
Then the second highest survival rate is actually female child with sixty nine percent.

10:39.310 --> 10:47.590
Then we have a male child with the 39 percent and by far the lowest survival rate had actually adult

10:47.620 --> 10:52.470
male passengers with only a sixteen point five percent.

10:52.480 --> 10:59.200
So again here we have a panda serious with an hierarchical index and we can also store yeah our pandas

10:59.200 --> 11:02.440
serious and the variable of women and children first.

11:02.440 --> 11:04.510
So this is the same as here above

11:09.240 --> 11:14.880
and now we can also visualize the survival rate of the groups by applauding our pandas serious women

11:14.880 --> 11:21.840
and children first then we are using a bomb plot and we are setting the fixed size to 14 8 and the font

11:21.840 --> 11:26.280
size to 14 and let's run near this cell and let's see what we get here

11:29.260 --> 11:36.700
so we have here the battered Titanic survival rate by sex age groups and we can see here on the y axis

11:36.730 --> 11:43.780
we have these survival rate and the group with the highest survival rate is actually female adult then

11:43.780 --> 11:50.380
the second highest survival rate is female child and that by far lower survival rate has the adult male

11:50.380 --> 11:58.190
group here are right we are finished now with this video and I hope to see you in the next video by.
