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)

Obtaining and organizing stock data from Google

Our first task is to write a couple of functions that help us with retrieving stock data from Google Finance. We have already seen that this data can be read using a pandas DataReader object, but we will need to organize the data a little differently than how it is provided by Google Finance, as we are going to perform various pivots of this information later.

The following function will get all the Google Finance data for a specific stock between the two specified dates, and also add the stock's symbol in a column (this will be needed later for pivots).

The data will consist of a fixed 3-year window, spanning the years of 2012 through 2014. The following reads data for this 3-year period for the MSFT ticker:

Now that we have a function that can get data for a single ticker, it will be convenient to have a function that can...