Legacy – Merging Dataframe Workout
- 02:15
Workout demonstrating how to merge two different DataFrames in Python using the PyCharm IDE.
Downloads
Merging DataFrame - Python Workout FilesTranscript
We can always combine two different DataFrames together, there are four ways to combine DataFrames. We can either join them by matching the rows from, say DataFrames one to DataFrames two, or we can also join them by matching the rows from DataFrames two to data frame one, or we can just join the data just retaining all the the rules in the board set, or we can just join everything, all the values all the rows. We shall be looking at all these examples. So firstly, on the screen, we've got two different data frames having columns A, B and A, D. with three different roles, we will first tried to join them by matching rows from DataFrames one to DataFrames two. Pandas has a special command PD . merge where we can combine DataFrames one and DataFrames two. How? from left to right on the column A. We try to print this and let's see what's going to happen.
Let's run the code. As we can see, we've seen that the DataFrames one and two have been combined. And there is a NAN value on column three, because there isn't any kind of intersection between column D in DataFrames two and column in DataFrames one. Now we can try to do the same thing from right to left, meaning merging rows from DataFrame two to DataFrame one. And it's going to return a similar answer. We can also join the data by returning rows in the both sets. In order to do that we select Enter for the house section. And as you can see, it's just combining the DataFrame one with DataFrame two where there is an intersection between both values in order to just retain all the values and all the rows we selected out option. And it's good to have all the columns all the rows from DataFrame one and two.