Merging and concatenating multiple DataFrames into one

This section focuses on how to combine two or more DataFrames using the pandas merge() and concat() methods. We'll also explore the usage of the merge() method to join DataFrames in various ways.

We will begin by importing the pandas module. Let's create two DataFrames, where both contain the same parameters with similar data, but which are for different records:

dataset1 = pd.DataFrame({'Age': ['32', '26', '29'],                         'Sex': ['F', 'M', 'F'],                         'State': ['CA', 'NY', 'OH']},                         index=['Jane', 'John', 'Cathy'])dataset2 = pd.DataFrame({'Age': ['34', '23', '24', '21'],                         'Sex': ['M', 'F', 'F', 'F'],                         State': ['AZ', 'OR', 'CA', 'WA']},                          index=['Dave', 'Kris', 'Xi', 'Jo'])dataset1dataset2

In this example, ...

Get Mastering Exploratory Analysis with pandas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.