Merging DataFrames

Merging dataframes deals with how to line them up by row. When we discussed stacking dataframes one on top of the other with pd.concat() and the append() method in Chapter 2, Working with Pandas DataFrames, we were performing the equivalent of the SQL UNION ALL statement (or just UNION if we also removed the duplicates as we saw in the previous chapter).

When referring to databases, merging is traditionally called a join. There are four types of joins: full (outer), left, right, and inner. These join types let us know how the result will be affected by values that are only present on one side of the join. This is a concept that's much more easily understood visually, so let's look at some Venn diagrams and then do some ...

Get Hands-On Data Analysis with Pandas now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.