Data Science Jumpstart with 10 Projects Transcripts
Chapter: Project 3: Merging AirBnB Temperature Data
Lecture: Merging Dataframes with the merge method and left_on, right_on parameters
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Okay, let's look at merging. It turns out that one of the 400 different things you can do is merge.
0:06
And again, you can come in here and you can pull up the documentation for merging and see that there are a bunch of parameters here.
0:11
So I'm just going to try and do this naively here. We'll say a b merge with temps. And when I try and do that, I get a failure.
0:18
And the message is actually useful. It says there's no common columns to merge on. So by default, pandas is going to look for common column names
0:27
and it's going to merge on those. Let's use some pandas to inspect what are the common column names. And it looks like none of them are common.
0:35
So here's the column names from our Airbnb data. And here's the column names from our temperature data.
0:41
So one of them has latitude and longitude spelled out. The other one has lat and lon. So in order to merge those, what we're going to say is
0:50
I want a b dot merge temps. And then we say left on. In this case, the left is referring to the a b, what we called merge on,
0:59
and the right is referring to temps. So the left on, those are columns from a b. a b has latitude and longitude spelled out.
1:07
Temps has lat and lon in there. And when we do that, we get something that looks like this.
1:12
If we scroll to the right, we can see that we now have lat, lon, and temperature in addition to our Airbnb data.
1:19
When you want to merge something in pandas, you can use the merge method. Again, by default, it's going to look for common column names.
1:26
But if you don't have common column names, you can specify the column names. Also, if you want to merge by the index,
1:32
you can tell it to do that as well.