Merging Multiple DataFrames on a Common Column in Pandas
Pandas: Custom Function Exercise-10 with Solution
Write a Pandas program to merge multiple DataFrames on a common column.
Following exercise shows how to merge three DataFrames on a common column.
Sample Solution :
Code :
Output:
ID Name Age Salary 0 1 Selena 25 50000 1 2 Annabel 30 60000 2 3 Caeso 22 70000
Explanation:
- Created three DataFrames df1, df2, and df3 with a common column 'ID'.
- Used pd.merge() twice to merge all three DataFrames on the 'ID' column.
- The result is a merged DataFrame that includes data from all three DataFrames.
Python-Pandas Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics