There are several ways to combine two dataframes in Python using the Pandas library.
concat()
method.For example, to concatenate two dataframes named df1
and df2
vertically:
main.py51 chars3 lines
To concatenate them horizontally, set the axis
parameter to 1:
main.py39 chars2 lines
merge()
method.For example, to merge two dataframes named df1
and df2
on a common column named key
:
main.py38 chars2 lines
There are several types of joins you can perform using the how
parameter in the merge method, such as inner join, left join, right join, and outer join.
These are some of the methods to combine two dataframes in Python using Pandas library.
gistlibby LogSnag