WEBVTT - This file was automatically generated by VIMEO

0
00:00:07.710 --> 00:00:08.390
Hi.

1
00:00:08.390 --> 00:00:12.970
In this video we will learn more about how to summarize data using

2
00:00:13.060 --> 00:00:13.893
group by.

3
00:00:17.420 --> 00:00:21.410
There are a few ways on how we can use the group by in pandas. Uh,

4
00:00:21.430 --> 00:00:25.850
the most common usage is to use it together with some aggregate function.

5
00:00:26.560 --> 00:00:28.930
Like in the first example here,

6
00:00:29.270 --> 00:00:34.050
we calculated the average duration of attacks per protocol and then

7
00:00:34.230 --> 00:00:35.890
sorted the result descending.

8
00:00:40.140 --> 00:00:44.120
But group by can be used also with other functions, not just aggregates,

9
00:00:44.120 --> 00:00:48.690
like mean minimum, maximum median or some for example,

10
00:00:48.960 --> 00:00:53.850
here in the second example I wanted to see what are the top

11
00:00:53.850 --> 00:00:58.250
three attacks, uh, with longest duration for each attack category.

12
00:01:00.530 --> 00:01:05.270
We see here the attack category index of the top three rows and their value.

13
00:01:08.690 --> 00:01:10.190
We can confirm this, uh,

14
00:01:10.190 --> 00:01:13.950
with calculating the maximum for each of the attack category.

15
00:01:23.060 --> 00:01:27.450
Other example, very similar to the last one. Maybe this,

16
00:01:28.170 --> 00:01:31.750
uh, let's get top three attacks per each of the attack category, uh,

17
00:01:31.750 --> 00:01:35.750
with longest duration. But we would like to see the whole row.

18
00:01:38.150 --> 00:01:41.070
We can use the apply method for this. Here.

19
00:01:41.090 --> 00:01:45.790
We basically applied the sort value method for each of the group and with head

20
00:01:45.790 --> 00:01:48.190
method we took just first three rows.

21
00:01:55.910 --> 00:01:58.130
The next example is, in my experience,

22
00:01:58.130 --> 00:02:01.130
the most common usage of group by together with aggregate.

23
00:02:01.390 --> 00:02:05.810
It is very flexible because we can nicely specify the columns,

24
00:02:05.810 --> 00:02:10.790
which we want to calculate and it's aggregate statistics. This way.

25
00:02:10.870 --> 00:02:12.870
I like it more because it is very similar,

26
00:02:13.020 --> 00:02:17.870
like SQL Works using Group I instead of using, uh, pivot table

27
00:02:22.550 --> 00:02:27.080
here in the next cell is the similar example as before. We just extended,

28
00:02:27.340 --> 00:02:29.880
uh, the calculation for service and its count

29
00:02:36.750 --> 00:02:41.160
here in this cell is an example on how to flatten the columns because they were

30
00:02:41.320 --> 00:02:46.000
a multi index to have just one level to also preserve the aggregate information

31
00:02:46.020 --> 00:02:46.853
in the column names.

32
00:02:51.250 --> 00:02:52.110
In our next video,

33
00:02:52.650 --> 00:02:57.190
we will learn more about how to style pandas data frames in Jupyter.
