O'Reilly logo

Mastering Exploratory Analysis with pandas by Harish Garg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required