Book Image

Learning Pandas

By : Michael Heydt
Book Image

Learning Pandas

By: Michael Heydt

Overview of this book

Table of Contents (19 chapters)
Learning pandas
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Plotting time-series prices


We will perform a graphical comparison of the closing values for AAPL and MSFT. Using the closing prices DataFrame, it is simple to plot the values for a specific stock using the .plot() method of Series. The following plots the adjusted closing price for AAPL:

In [9]:
   # plot the closing prices of AAPL
   close_px['AAPL'].plot();

The following code plots the adjusted closing price for MSFT:

In [10]:
   # plot the closing prices of MSFT
   close_px['MSFT'].plot();

Both sets of closing values can easily be displayed on a single chart in order to give a side-by-side comparison:

In [11]:
   # plot MSFT vs AAPL on the same chart
   close_px[['MSFT', 'AAPL']].plot();

The output is seen in the following screenshot:

Plotting volume-series data

Volume data can be plotted using bar charts. We first need to get the volume data, which can be done using the pivotTickersToColumns() function created earlier:

In [12]:
   # pivot the volume data into columns
   volumes = pivotTickersToColumns...