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

Summarized data and descriptive statistics


pandas provides several classes of statistical operations that can be applied to a Series or DataFrame object. These reductive methods, when applied to a Series, result in a single value. When applied to a DataFrame, an axis can be specified and the method will then be either applied to each column or row and results in a Series.

The average value is calculated using .mean(). The following calculates the average of the prices for AAPL and MSFT:

In [119]:
   # calc the mean of the values in each column
   one_mon_hist.mean()

Out[119]:
   MSFT     47.493182
   AAPL    112.411364
   dtype: float64

pandas has taken each column and independently calculated the mean for each and returned the results as values in a Series that is indexed with the column names.

The default is to apply the method on axis=0, applying the function to each column. The following code calculates the mean across axis=1:

In [120]:
   # calc the mean of the values in each row
  ...