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)

Performing a moving-average calculation

The moving average of a stock can be calculated using .rolling().mean(). The moving average will give you a sense of the performance of a stock over a given time-period, by eliminating "noise" in the performance of the stock. The larger the moving window, the smoother and less random the graph will be, but at the expense of accuracy.

The following sample calculates the moving average for MSFT over 30- and 90-day periods, using the daily close value. The difference in the reduction of noise can be easily determined from the visual: