Search⌘ K

Introduction to Merging/Concatenating DataFrames

Explore the fundamentals of combining multiple DataFrames in Pandas through merging and concatenation. Understand different join types like left, right, and outer joins, and learn to apply these in real-world scenarios such as travel and medical datasets. This lesson prepares you to skillfully handle common interview questions on data integration and analysis.

Concept

Till now, you’ve been dealing with a single DataFrame object. Often, there you may need to combine multiple datasets into one object, based on a common column.

Syntax

Assuming you have two DataFrame objects, df1 and df2, the most basic type of merge can be done with the following syntax:

merged = pd.merge(df1, df2)

Multiple options exist in the merge; you could do a Left/Right/Outer join, or choose the columns to perform the merge.

There are also other ways to combine DataFrame objects, such as by using .join() or .append() ...