WEBVTT - This file was automatically generated by VIMEO

0
00:00:07.770 --> 00:00:08.370
Hi.

1
00:00:08.370 --> 00:00:12.830
In this video we will learn more about merging pandas data frames.

2
00:00:16.550 --> 00:00:20.560
Merging or joining data frames is a must have knowledge for everyone.

3
00:00:20.560 --> 00:00:25.400
Working with Data of Pandas has two methods to join the

4
00:00:25.400 --> 00:00:29.440
data frames. First is the merge method, which is more flexible,

5
00:00:29.500 --> 00:00:33.750
but we have to specify more parameters and the join method,

6
00:00:34.000 --> 00:00:36.910
which reduces the index to join the data frames.

7
00:00:40.020 --> 00:00:44.480
Now let's add to our dataset new variables from this c s csv,

8
00:00:45.100 --> 00:00:47.520
uh, TCP ports, csv, uh,

9
00:00:47.520 --> 00:00:52.120
which contains a list of ports and their services running on these ports.

10
00:00:52.180 --> 00:00:57.070
And their description. These are the first few rows of this data frame.

11
00:01:00.050 --> 00:01:04.710
We also see that they are no, uh, duplicate values in the ports.

12
00:01:11.670 --> 00:01:16.290
We see that, uh, both data sets have a common column, which is the poor number.

13
00:01:16.550 --> 00:01:21.530
Uh, that means we can expand our original data frame. Joining on this column,

14
00:01:23.170 --> 00:01:26.420
this is how we do it using the merge method, uh,

15
00:01:26.420 --> 00:01:31.140
where we specify the columns on which to join and type of the join.

16
00:01:31.980 --> 00:01:36.460
I put here left because I want to preserve the original data frame,

17
00:01:36.880 --> 00:01:41.710
all these rows. There are other type of joins, like inner join,

18
00:01:41.840 --> 00:01:45.270
right? Join full outer join even on anti joinin.

19
00:01:45.810 --> 00:01:47.630
But this is not the topic of this video,

20
00:01:48.010 --> 00:01:52.030
but I highly encourage to you to learn about this, uh,

21
00:01:52.030 --> 00:01:56.390
because it is a must-have skill for everyone. When working with data.

22
00:02:01.960 --> 00:02:05.940
Now we see that to each attack, uh, we see also service,

23
00:02:06.310 --> 00:02:07.820
which was exploited in that

24
00:02:10.690 --> 00:02:12.630
and their description as well. The

25
00:02:21.230 --> 00:02:25.030
joint method does the same, but the joins by the index.

26
00:02:25.370 --> 00:02:30.220
We have to set the index first and then call the join method. Uh,

27
00:02:30.280 --> 00:02:33.420
we have to specify the type of the join as well.

28
00:02:41.300 --> 00:02:43.560
We see that the results are the same,

29
00:02:51.600 --> 00:02:55.100
but the order is a little bit different now because we changed the index.

30
00:02:57.820 --> 00:02:59.120
We see it by this shape.

31
00:03:05.510 --> 00:03:07.330
Now to union. Uh,

32
00:03:07.330 --> 00:03:11.890
sometimes we will need also to expand the dataset on the other axis.

33
00:03:11.960 --> 00:03:14.770
That means we will have more rows with same columns.

34
00:03:16.760 --> 00:03:19.860
We can use the pandas concat method for this,

35
00:03:20.070 --> 00:03:25.060
where we put the data frames into a list. Uh, they must have the same columns.

36
00:03:26.130 --> 00:03:29.470
Uh, here, just for illustration, I created, um,

37
00:03:30.040 --> 00:03:32.310
three data frames, uh,

38
00:03:32.310 --> 00:03:35.430
based just on a simple filter on the attack category column

39
00:03:37.070 --> 00:03:41.130
and concatenated them into a new data frame.

40
00:03:41.750 --> 00:03:46.580
DF union. Notice the shape of the resulting data frame.

41
00:03:51.400 --> 00:03:52.380
In our next video,

42
00:03:52.760 --> 00:03:57.460
we will learn how to summarize the data using cross up and PO table.
