Book Image

Learning pandas - Second Edition

By : Michael Heydt
Book Image

Learning pandas - Second Edition

By: Michael Heydt

Overview of this book

You will learn how to use pandas to perform data analysis in Python. You will start with an overview of data analysis and iteratively progress from modeling data, to accessing data from remote sources, performing numeric and statistical analysis, through indexing and performing aggregate analysis, and finally to visualizing statistical data and applying pandas to finance. With the knowledge you gain from this book, you will quickly learn pandas and how it can empower you in the exciting world of data manipulation, analysis and science.
Table of Contents (16 chapters)

Concatenating rows

The rows from multiple DataFrame objects can be concatenated to each other using the pd.concat() function and by specifying axis=0. The default operation of pd.concat() on two DataFrame objects along the row axis operates in the same way as the .append() method.

This is demonstrated by reconstructing the two datasets from the earlier append example and concatenating them instead.

If the set of columns in all DataFrame objects is not identical, pandas will fill those values with NaN.

Duplicate index labels can result as the rows are copied verbatim from the source objects. The keys parameter can be used to help differentiate which data frame a set of rows originated from. The following demonstrates by using keys to add a level to the index representing the source object:

We will examine hierarchical indexes in more detail in Chapter 6, Working with Indexes...