Measures of Center and Spread

Measures of Center With Python

Mean

Your Turn: Calculate Your Group’s Mean Nitrate

The website doesn’t save your nitrate readings list from the previous page, so you’ll need to re-enter your data into the list below (Line 3) again.

🎯 Checkpoint 6. a: Calculating Group Mean Nitrate

Replace the 10, 20, 30, and 40 placeholders with the nitrate readings from your group!

Click the ▶️ Run Code button to run the block.



Class Data
One of the benefits of using Python is that it can handle much larger amount amounts of data with ease. For example, let’s consider the nitrate and nitrite data your whole class collected. We’ll do that by importing the data collected in the Google Form. That form sends the data to a spreadsheet, or CSV (comman separated values) file.

🎯 Checkpoint 6. b: Import class data.
ImportantYour teacher will provide the link to the CSV file for you to use.

Replace the placeholder (Line 4) with CSV URL from your teacher. Be sure the keep the quotation marks! This will pull the class nitrate and nitrite data from the CSV file so you can use it later down the page.

Click the ▶️ Run Code button to run the block.



Your Turn: Calculate the Class Nitrate and Nitrite Mean

Use the code written to calculate the mean for your class’s nitrate and nitrite data.

🎯 Checkpoint 6. c: Calculate means for class data.

Replace the ??? placeholders (Lines 3 & 4) with the variables that hold the class nitrate and nitrite data. That is, class_nitrate and class_nitrite, respectively.

Click the ▶️ Run Code button to run the block.



Median

Your Turn: Calculate the Class Nitrate and Nitrite Median

🎯 Checkpoint 6. d: Calculate medians for class data.

Similarly, replace ??? with the correct variable names to calculate the median for the class nitrate and nitrite data.

Click the ▶️ Run Code button to run the block.



Measures of Spread with Python

Range

The range is a fairly simple calculation. It’s the biggest number minus the smallest number. Or, put differently, the maximum minus the minimum in a dataset.

max() - min()

🎯 Checkpoint 6. e: Find the range of the class nitrate and nitrite data.

Replace ??? with the correct variable names to calculate the ranges of the data.

Click the ▶️ Run Code button to run the block.



Standard Deviation

The standard deviation tells us how spread out the numbers are from the mean. Put diffently, it tells us the average distance the data in the dataset is from the mean.

🎯 Checkpoint 6. f: Calculate standard deviations for class data.

Replace ??? with the correct variable names to calculate the standard deviations of the data.

Click the ▶️ Run Code button to run the block.




Quick Reference: Python Functions

Function What It Does Example
np.mean() Calculates average np.mean([7.1, 7.2, 7.3]) = 7.2
np.median() Calculates median np.median([7.1, 7.2, 7.3]) = 7.2
np.std() Calculates standard deviation np.std([7.1, 7.2, 7.3]) = 0.3
len() Counts items len([1, 2, 3]) = 3
max() Finds maximum max([1, 2, 3]) = 3
min() Finds minimum min([1, 2, 3]) = 1