Hello, Water Scientist!
Water Quality and Summary Statistics
In this lesson, you will learn how to use the Python programming language to calculate summary statistics and investigate nitrates and nitrates in water samples.
Materials Needed:
- 💻 Your computer
- A web browser (Chrome, Firefox, or Safari)
- A calculator
💻 Navigate to: https://appalachianaicorps.org/ > Modules > Water Quality Monitoring > Lesson 1
Note: If you see a 💻 laptop 💻 icon in the slides, that means there is a corresponding activity in the module to complete!
You move pages by clicking on this left-hand sidebar
🎯 Checkpoint 1.a: Print Statements
🎯 Checkpoint 1.a: Print Statements
Click the ▶️ Run Code button to run the block.
Hello, Water Scientist!
🎉 You just ran Python code! The output is right below the block! See how it printed Hello, Water Scientist!
Note that strings are always surrounded by quotation marks.
🎯 Checkpoint 1.b: Mathematical Operators
Click the ▶️ Run Code button to run the blocks.
➕ Addition:
➖ Subtraction:
✖️ Multiplication:
➗ Division:
🎯 Checkpoint 1.b: Mathematical Operators
Click the ▶️ Run Code button to run the blocks.
➕ Addition:
➖ Subtraction:
🎯 Checkpoint 1.b: Mathematical Operators
Click the ▶️ Run Code button to run the blocks.
✖️ Multiplication:
➗ Division:
🎯 Checkpoint 1.d: Print Statements with Math
Click the ▶️ Run Code button to run the block.
Make a prediction. What will Python print?
🎯 Checkpoint 1.e: Edit the print statements!
Click the ▶️ Run Code button to run the block.
Nitrate and Nitrite EPA Limits
Nitrates: 10 mg/L
Nitrites: 1 mg/L
🧠 Using data from EWG, what is the most recently reported nitrate concentration by your water utility? Are your’s over the limit?


Assign roles to each person in your group:
Role 1: Data Recorder (Lab Report)
Role 2: Data Recorder (Computer)
Role 3: Lab Technician
Read the procedure on your lab sheet. Make sure everyone in your group understands the procedure and has the materials needed for their role.
🚀 LET’S BEGIN 🚀
When finished: With the help of the Data Recorder (Lab Report), make sure everyone in your group has a copy of the data table on their own sheet.
We use measures of center to find the central value of a group of numbers.
Sample Dataset: 1, 2, 6, 5, 1
The mean is often called the “average”.
\(\Large \frac{1 + 2 + 6 + 5 + 1}{5} = 3\)
The mean value of this sample dataset is 3.
We use measures of center to find the central value of a group of numbers.
Sample Dataset: 1, 2, 6, 5, 1
The median is a different kind of measure of center.
\(\large 1, 1, 2, 5, 6\)

🎯 Checkpoint 4.a: Calculations—Mean & Median
Find the mean and median of your team’s lab data:
✏️ Record your results on your lab sheet.
Sample Dataset: 1, 2, 6, 5, 1
In Python, we store multiple numbers in something called a list.
🎯 Checkpoint 5.a: Storing data as lists!
Replace the ??, ??, ??, and ?? placeholders with the nitrate and nitrite readings from your group!
Click the ▶️ Run Code button to run the block.
My group's nitrate readings: [10, 20, 30, 40]
My group's nitrite readings: [10, 20, 30, 40]
🎯 Checkpoint 5.b: Basic functions with lists.
How many items are in a list?
Smallest number in a list.
Biggest number in a list.
Sample Datasets: A = [1, 2, 6, 5, 1]
How many items are in a list?
Number of samples tested: 5
Lowest nitrate: 1
Sample Datasets: A = [1, 2, 6, 5, 1]
Highest nitrate: 6
🎯 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.
On average, do you think your water is safe in terms of nitrate and nitrite concentrations? Why or why not?
Your teacher will provide the link to the CSV file for you to use.
🎯 Checkpoint 6.b: Import class data.
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.
Nitrate values: [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 8.0, 9.0, 10.0, 10.5, 11.0, 12.0, 13.5, 15.0, 18.0, 22.5]
Nitrite values: [0.0, 0.0, 0.1, 0.1, 0.15, 0.2, 0.2, 0.25, 0.3, 0.3, 0.35, 0.4, 0.4, 0.5, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.2, 1.5, 1.8, 2.5, 3.0]
🎯 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.
🎯 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.
7.58
0.71
Your answers will differ. This is example data.
🎯 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.
🎯 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.
6.5
0.4
Your answers will differ. This is example data.
max() - min()
🎯 Checkpoint 6.e: Calculate ranges for class data.
Replace ??? with the correct variable names to calculate the ranges of the data.
Click the ▶️ Run Code button to run the block.
🎯 Checkpoint 6.e: Calculate ranges for class data.
Replace ??? with the correct variable names to calculate the ranges of the data.
Click the ▶️ Run Code button to run the block.
22.0
3.0
Your answers will differ. This is example data.
🎯 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.
🎯 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.
5.4
0.8
Your answers will differ. This is example data.
Whew! That was a lot of work. Wouldn’t it be great if Python could do it for us? Good news. It can! But first, let’s re-import our data on this page.
🎯 Checkpoint 8.a: Import Class Data.
Once more, 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.
🎯 Checkpoint 8.b: Create a boxplot for the class nitrate data.
Click the ▶️ Run Code button to run the block and create a boxplot for the class nitrate data.
import matplotlib.pyplot as plt
plt.figure(figsize=(6, 6))
plt.boxplot(class_nitrate, vert=True, patch_artist=True,
boxprops=dict(facecolor='plum'))
plt.ylabel('Nitrate (mg/L)', fontsize=12)
plt.xticks([])
plt.title('Boxplot of Class Nitrate', fontsize=13)
plt.grid(True, alpha=0.3, axis='y')
plt.show()🎯 Checkpoint 8.b: Create a boxplot for the class nitrate data.
Click the ▶️ Run Code button to run the block and create a boxplot for the class nitrate data.
import matplotlib.pyplot as plt
plt.figure(figsize=(6, 6))
plt.boxplot(class_nitrate, vert=True, patch_artist=True,
boxprops=dict(facecolor='plum'))
plt.ylabel('Nitrate (mg/L)', fontsize=12)
plt.xticks([])
plt.title('Boxplot of Class Nitrate', fontsize=13)
plt.grid(True, alpha=0.3, axis='y')
plt.show()This uses example data.

Now, let’s create a boxplot for the class nitrite data.
🎯 Checkpoint 8.c: Create a boxplot for the class nitrite data.
Click the ▶️ Run Code button to run the block and create a boxplot for the class nitrite data.
Now, let’s create a boxplot for the class nitrite data.
🎯 Checkpoint 8.c: Create a boxplot for the class nitrite data.
Click the ▶️ Run Code button to run the block and create a boxplot for the class nitrite data.
This uses example data.

Outliers are data points that are very different from the rest of your data.
- Can really change your statistics—like mean and standard deviation.
- On boxplots, outliers are represented by a circle (or sometimes a star) beyond the whiskers.
🧠 Do either the class nitrate or nitrite boxplot have outliers? How do you know?
Outliers can happen for different reasons:
Your job as a scientist: Figure out which reason it is!
AAIC — Water Quality