![]() |
VOOZH | about |
The Pandas module contains various features to perform various operations on Dataframes like join, concatenate, delete, add, etc. In this article, we are going to discuss the various types of join operations that can be performed on Pandas Dataframe. There are five types of Joins in Pandas.
To understand different types of joins, we will first make two DataFrames, namely a and b.
Dataframe a:
Output:
DataFrame b:
Output:
We will use these two Dataframes to understand the different types of joins.
Inner join is the most common type of join you’ll be working with. It returns a Dataframe with only those rows that have common characteristics. This is similar to the intersection of two sets.
Example:
Output:
👁 ImageWith a left outer join, all the records from the first Dataframe will be displayed, irrespective of whether the keys in the first Dataframe can be found in the second Dataframe. Whereas, for the second Dataframe, only the records with the keys in the second Dataframe that can be found in the first Dataframe will be displayed.
👁 left-join
Example:
Output:
👁 ImageFor a right join, all the records from the second Dataframe will be displayed. However, only the records with the keys in the first Dataframe that can be found in the second Dataframe will be displayed.
👁 Pandas Right Outer JoinExample:
Output:
👁 ImageA full outer join returns all the rows from the left Dataframe, and all the rows from the right Dataframe, and matches up rows where possible, with NaNs elsewhere. But if the Dataframe is complete, then we get the same output.
👁 Pandas Full Outer JoinExample:
Output:
👁 ImageTo merge the Dataframe on indices pass the left_index and right_index arguments as True i.e. both the Dataframes are merged on an index using default Inner Join.