O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calculating the mean

The mean, commonly referred to as the average, gives us a measurement of the central tendency of data. It is determined by summing up all the measurements and then dividing by the number of measurements.

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

Pandas has taken each column and independently calculated the mean for each. It 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. This code switches the axis and returns the average price for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required