WEBVTT

00:02.630 --> 00:08.450
In this video we will split our data framed by more than one key so in principle we can split our data

00:08.450 --> 00:12.200
friends by one two three or whatever number of keys.

00:12.200 --> 00:14.240
So this is no problem.

00:14.240 --> 00:18.460
And first of all we import pandas as always.

00:18.770 --> 00:25.370
And then now we are working with the Summer Olympics data frame and we will have a look at the first

00:25.370 --> 00:33.620
five rows here and also add some meta information and this time we are working with the whole data frame.

00:34.900 --> 00:37.120
So no toy examples this time.

00:37.120 --> 00:40.900
And let's have a look here at the country column.

00:41.920 --> 00:43.390
So now let's first have a look.

00:43.390 --> 00:48.360
How many different or unique countries we have in our data frame.

00:49.490 --> 00:55.100
So up to now athletes from one hundred forty seven countries have already won medals in some Olympic

00:55.100 --> 01:02.000
Games and in the last video where we have split our Titanic data frame into a major data frame and a

01:02.000 --> 01:08.960
female data frame we have seen that we can also do this as says hello operator and create a group by

01:08.960 --> 01:10.040
group.

01:10.040 --> 01:17.060
So this is quite easy if we only have two groups of males and females but the fear of 147 groups like

01:17.060 --> 01:24.290
in this case then doing this manually with the log operator is getting quite messy and this the group

01:24.290 --> 01:27.100
by a method we can do this actually in one line.

01:27.320 --> 01:28.310
So let's do this.

01:28.310 --> 01:34.520
We are splitting our Summer Olympics data frame by the key country and we're safe.

01:34.520 --> 01:42.650
Our group by object in the Variable split 1 and that's transform our group by up checked into a list

01:43.250 --> 01:45.130
and stored in the variable idea.

01:46.460 --> 01:48.800
So let's have a look here at our list.

01:48.810 --> 01:51.650
Uh first of all let's secure the links.

01:52.070 --> 01:57.680
So we have one of the 47 countries and the length of our list is 147.

01:57.950 --> 02:04.660
And for each country actually we have here in our list a top of the consisting of the country code.

02:04.680 --> 02:10.210
Yes starting with Afghanistan and then the second element in the top.

02:10.220 --> 02:15.950
Actually the data frame with all rows where we have athletes from Afghanistan.

02:15.950 --> 02:20.840
So in total here we have two medals both medals awarded here and tech one though.

02:21.610 --> 02:24.230
And here we have the second element of our list.

02:24.400 --> 02:26.140
So the country H.

02:26.270 --> 02:29.150
Oh so actually I do not know which country it is.

02:29.390 --> 02:32.450
And then the third element is here Algeria.

02:33.540 --> 02:41.040
So we can also randomly select a data frame and we slice for the top of that next position 100 and we

02:41.040 --> 02:44.210
slice for the data frame so let's see what we've got here.

02:47.250 --> 02:55.590
And we get you a data frame with all medals won by athletes from the Philippines and now instead of

02:55.590 --> 03:01.830
splitting our data frame only by the country you want to split our data frame by a country and send

03:01.830 --> 03:10.240
a so give us our group by method we have the parameter by and before we just passed here one column

03:10.240 --> 03:14.980
name but we can pass here a list of multiple column names.

03:14.980 --> 03:22.330
So here we are passing the column name country and gender and by doing so we can split our data frame

03:22.480 --> 03:23.860
by country and gender.

03:24.490 --> 03:29.750
So let's do this and we save our group by object in the variable split 2.

03:30.400 --> 03:37.450
So let's run in the center and then we are transforming our group by object into a list and save the

03:37.450 --> 03:41.230
list and the variable 2 and let's print here L2

03:44.190 --> 03:46.890
and first of all you can see here the first element.

03:47.940 --> 03:53.650
We fear all men from Afghanistan that already won a medal in some Olympic Games.

03:56.220 --> 03:59.320
And we can also check here the length of our list too.

04:00.120 --> 04:08.670
So intuitively we could say OK we have 147 countries and we have male and female saw the number of possible

04:08.670 --> 04:12.480
combinations should be two times 147.

04:12.590 --> 04:19.580
It's 294 So potentially we have two hundred ninety four groups.

04:19.580 --> 04:25.850
But I do think at least for the smaller countries that we have countries where only male athletes are

04:25.850 --> 04:29.330
female at athletes have already won medals.

04:30.020 --> 04:36.240
So I do not expect to have here in our to list a length of 294.

04:36.350 --> 04:37.700
So let's check this out

04:40.560 --> 04:48.220
and we have only two hundred thirty six groups and let's randomly select the group at the next position

04:48.230 --> 04:51.120
one hundred four.

04:51.120 --> 04:57.180
And here we can see that we have the group with female athletes from Ireland.

04:57.270 --> 05:03.690
So actually we have here one two three four five six medals that has been awarded to female athletes

05:03.690 --> 05:05.050
from Ireland.

05:05.220 --> 05:10.840
And apparently here we have a topless so we can also check here for the first element in our topic.

05:12.090 --> 05:15.960
And here it's not a string but also a topic consisting of two strings.

05:15.950 --> 05:23.310
So here are two groups so we have Ireland and women and we can also slice our total for the second element

05:23.310 --> 05:26.310
or the second element here is the data frame.

05:27.780 --> 05:35.790
And here we have the data frame with all rows or medals where we have female athletes from Ireland and

05:35.790 --> 05:37.570
still you on the left side.

05:37.800 --> 05:44.760
We have here the index labels from our original data frame.

05:44.810 --> 05:45.200
All right.

05:45.200 --> 05:46.790
So now on this video we split it.

05:46.790 --> 05:52.120
Our summer Olympics data frame not only by one key but by two keys.

05:52.130 --> 05:55.490
And we could also do the same for our markets.

05:55.490 --> 06:02.000
So for example we could say that we want to split our data frame by Country Athlete and let's say the

06:02.000 --> 06:06.650
year of the addition of the Olympic Games then yeah.

06:06.660 --> 06:09.810
Michelle Marie Smith what actually form one group.

06:09.960 --> 06:17.040
So female athletes from Ireland who won in the addition and in 1960 a medal and a second group would

06:17.040 --> 06:23.280
be a female athletes also from Ireland that won in the year on the addition 2000 a medal.

06:23.550 --> 06:28.850
So you in this data frame we only got have Sonya Sullivan.

06:28.890 --> 06:29.310
All right.

06:29.320 --> 06:33.940
We are finished now with this video and I do think we have now a good impression.

06:33.940 --> 06:40.600
How a group buys splits our original data frame and many data frames on many groups and in the next

06:40.600 --> 06:44.300
video we will learn how split apply combined works.

06:44.320 --> 06:49.300
So this is the real power of group buy and I hope to see on the next video by.
