Hi.
In this video we will learn more about merging pandas data frames.
Merging or joining data frames is a must have knowledge for everyone.
Working with Data of Pandas has two methods to join the
data frames. First is the merge method, which is more flexible,
but we have to specify more parameters and the join method,
which reduces the index to join the data frames.
Now let's add to our dataset new variables from this c s csv,
uh, TCP ports, csv, uh,
which contains a list of ports and their services running on these ports.
And their description. These are the first few rows of this data frame.
We also see that they are no, uh, duplicate values in the ports.
We see that, uh, both data sets have a common column, which is the poor number.
Uh, that means we can expand our original data frame. Joining on this column,
this is how we do it using the merge method, uh,
where we specify the columns on which to join and type of the join.
I put here left because I want to preserve the original data frame,
all these rows. There are other type of joins, like inner join,
right? Join full outer join even on anti joinin.
But this is not the topic of this video,
but I highly encourage to you to learn about this, uh,
because it is a must-have skill for everyone. When working with data.
Now we see that to each attack, uh, we see also service,
which was exploited in that
and their description as well. The
joint method does the same, but the joins by the index.
We have to set the index first and then call the join method. Uh,
we have to specify the type of the join as well.
We see that the results are the same,
but the order is a little bit different now because we changed the index.
We see it by this shape.
Now to union. Uh,
sometimes we will need also to expand the dataset on the other axis.
That means we will have more rows with same columns.
We can use the pandas concat method for this,
where we put the data frames into a list. Uh, they must have the same columns.
Uh, here, just for illustration, I created, um,
three data frames, uh,
based just on a simple filter on the attack category column
and concatenated them into a new data frame.
DF union. Notice the shape of the resulting data frame.
In our next video,
we will learn how to summarize the data using cross up and PO table.