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)

Appending new rows

Appending of rows is performed using the .append() method of the DataFrame. The process of appending returns a new DataFrame with the data from the original DataFrame added first and then rows from the second. Appending does not perform alignment and can result in duplicate index labels.

The following code demonstrates appending two DataFrame objects extracted from the sp500 data. The first DataFrame consists of rows (by position) 0, 1 and 2, and the second consists of rows (also by position) 10, 11 and 2. The row at position 2 (with label ABBV) is included in both to demonstrate the creation of duplicate index labels.

The set of columns of the DataFrame objects used in an append do not need to be the same. The resulting data frame will consist of the union of the columns in both, with missing column data filled with NaN. The following demonstrates this by...