Getting the mean, median, mode, and range for a single column

Once again harkening back to algebra, we want to view the mean, median, mode, and range for a single column of our data. If you need a refresher in the definitions of these terms, here you go:

  • Mean: the average
  • Median: the middle value
  • Mode: the value that occurs most often
  • Range: the difference between the minimum and maximum values

How to do it…

  1. To get the mean, median, mode, and range for a single column in a Pandas DataFrame, begin by importing the required libraries:
    import pandas as pd
  2. Next, import the dataset from the CSV file:
    accidents_data_file = '/Users/robertdempsey/Dropbox/private/Python Business Intelligence Cookbook/Data/Stats19-Data1979-2004/Accidents7904.csv' accidents = pd.read_csv(accidents_data_file, ...

Get Python Business Intelligence Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.