Join Rows When Concatenating on Columns
00:00
In this final lesson of the second section, about combining data using concat()
, you’ll learn how you can create an inner join on the rows while you’re concatenating your two DataFrames on the columns.
00:13 Now let’s look at the same example using the columns axis for your primary concatenation, which means the join is going to operate on the row axis instead of the column axis.
00:26 So you can pause the video for a second and think about what you think the output is going to be of this. Now go ahead and run it,
00:34
and you can see what happened is that again, you have the fruits
DataFrame with its two, originally two times four, and the veggies
DataFrame, which is still complete with its three times three.
00:53
But because the veggies
DataFrame only has three rows, and the fruits
DataFrame has four, pandas got rid of the final row in the fruits
DataFrame after concatenating the two DataFrames on the columns axis. So again, the concatenation always relates to what you define here in the axis
argument, and that just sticks things together. And then with join
, you can define how to deal with the second column. In the previous example, the second axis were the columns, and here you have the primary axis being the columns, so the secondary axis is gonna be the rows.
01:35 And for the rows, if you define an inner join, that means that anything that doesn’t have a corresponding thing in the second DataFrame just gets cut off by pandas.
01:48
In this lesson, you learned how you can perform an inner join on the rows while you’re concatenating your two DataFrames on columns. And to do that, you just had to pass the "columns"
string as an argument to the axis
parameter to define that the primary axis for the concatenation is going to be the columns instead of the default rows.
02:10
Then you had to keep passing the string "inner"
to the join
parameter to perform an inner join instead of the default outer. Now that wrap up talking about some of the most important keyword arguments that you can pass to change the behavior of pd.concat()
.
02:26
In the next lesson, you’ll go over a summary of the different keyword arguments and functionalities that you encountered while using pd.concat()
.
Become a Member to join the conversation.