Welcome back to the class of our course about the complete introduction to that science with Python.
So in this class, we are still going to talk about pandas and some basic operations that you guys can
perform with this amazing plug in to Python.
So basically today we are going to learn how to merge some data frames together and what exactly means
merge.
It's pretty simple.
It's let's say, for example, you guys have more than one that frame.
So let's say two, three or four, dereference you can put them together in only one data frame.
So basically, if each of those that are frames are the same, so there is the same thing written on
them, you can just put them all together and only one data frame.
And even if there are some things that are not pretty much the same, you can keep some columns coming
by, adding something to the to this operation.
So we are going to see how it works.
A bit more in depth right now.
All right.
So to be able to make everything to to run it pretty much well, to to understand how this works, what
will do is pretty simple.
We are going to create a data frame.
So pretty simple.
We are going to do what we have learned to in the past two classes.
So first of all, we are going to import our pandas.
So basically here we go as speedy.
And from now on, what will do?
We will create two databases for two basic databases.
Let's say it's going to be food.
So basically we'll have the number of the food, the name of the food.
And finally, let's say the rate or the price of the food.
So let's say we'll have here database.
That will be food one.
And from this moment, we are going to create or thereabouts, so what we'll have at first is pretty
simple.
We'll have the number of the food.
So basically you can just give a number to your food.
And in this case, the number will be from one to five since we are working with food.
So one, two, three, four and five.
All right.
Then the next thing that we will have will be the name of the food.
So basically here will give a name to our food.
So let's call it name and let's do the exact same thing.
So let's say we'll have apples.
Who have on us,
who have.
I don't know, we can have pizza or anything that you want, you can just write down letters because
it's just for the purpose of understanding how this works.
So let's say apple, bananas, chips,
popcorn,
and let's say, I don't know, beans for pizza.
Pizza is better here.
All right.
So we have our five foods, and the last thing will be price.
So basically, we'll have a variable that will be price to have a list of all the prices.
So here we go.
We have, let's say, two dollars.
Three dollars, four dollars.
Eight dollars and six dollars.
All right, so we have our first database right here, so basically our first dictionary or list of
databases that we will use to create our database.
Then next thing will create a second one a bit lower.
So we have found one and the exact same thing.
So we'll create another one that will be called food number two.
And what what is going to be very interesting is that will keep everything the same.
So to understand how it works and emerging, we are going to keep everything the same.
And what we'll do right now, we will create data frames.
So basically a little right here.
So we'll have our table one or you can call it food one, table one, how you want it.
And from this moment, we'll create or the so how exactly we create are the different.
Like always we're going to use pendas pandas to create or the difference.
We will use the extension that you guys can see right here.
So that data frame here, you can find it right there.
And from this moment, we are going to use food one, so food one for our benefit and we'll do the exact
same thing for our table number two.
Here we go.
So don't forget, just change the name when you copy and paste everything.
So right now what we have, we have our list of everything that we are going to use every dictionary.
So for food one and food number two, it should be pretty much the same thing.
So what I want to do right now, so we have our friends that are created right here so they can see
table one will be the data from a food one and the table two will be the delivery of your food number
two.
So very important, number two as well.
And from this moment, we want to fusun everything together or merge everything together.
So basically what we'll do, we will create travel that will be named Fusun.
So we'll call it Fusion.
And here we are going to merge everything together.
So basically, we are going to write down once a year and we are going to use our PDA extension to that
refers to pendas.
And here we'll use the formula merge.
So basically the function merge to merge table one into two together.
So table one as well as table two together.
So right now here, what we done.
What have we done?
It's pretty simple here.
We have merged the two tables together, so this is the formula to merge the two tables together.
So as you can see, it's pretty simple.
And we want to do right now is simply print the variable fusion.
You're going to print fusion.
If we run the.
As you can see what happened, it simply printed everything together, so basically you have merged
the two the two databases together.
So let's say, for example, right now, instead of right here, we write down corn and we run once
again are up.
What's going to happen is that the apple will disappear because it's not the same thing.
So what we'll do, it will merge the two the two databases together.
But if it's not the same thing, well, it's just not going to merge it and it's not going to appear
right here.
So basically, it will just merge everything.
That is the same in the two columns right here in the two databases that are being number one in the
database.
Number two, right now, let's say that you guys want to keep some comments coming and basically make
it work, even if here we have corn and here we have apple.
So basically, let's say here we have corn, here we have apple.
The price of the corn is not two dollars.
It's going to be I don't know.
Eight dollars, for example, in here, we don't have chips, we have, let's say, beans.
All right, so let's say we want to keep the column a name so common.
What we'll do, it's pretty simple right here after our table to we will simply add a comma and write
down on so on.
Equal to what exactly?
Want to keep coming, so we want to keep the names coming, so basically we'll just write down a name
because we want to keep the name coming.
And if we on the up, as you can see what's going to happen, we'll have our names.
So right here, we'll have our Barona and we'll have everything that one.
So basically, we keep the name coming right here.
If you want to do the exact same thing for numbers, we can do it so we can just put everything we can
just take it and write down the numbers and we run everything together.
And as you can see, it's going to do the exact same thing.
So the numbers will be coming in this case.
So you can see the court appears and we have our corn for eight dollars and we have our apple for two
dollars as well.
So you can see it's pretty simple to understand.
So basically, the first thing that you guys want to do to be able to make sure well, to be able to
measure, not function, is to be able to measure database's.
It's pretty simple what you want to do at first.
You want to create your database.
So basically here you will have your list that will be used for databases.
Then you simply put those you create dereference with those data bases that you have.
Well, with your list, you put all your lists in form of data frames right here with this function
right there, and then you simply merge everything with the function right here.
So I hope you guys understood this operation.
So it's pretty simple what it does.
It simply put together two databases that are not together.
And when I see together, it's it will simply put together everything that is the same in the two databases.
So everything that is not the same will just not be put it inside of this database.
But it's possible to keep some Collins common as well with the UN function inside of our merge function.
So that's a first class guys, all in our next class.