Head office, Rana Pratap Bagh, Delhi+91 97116 99511

Science project idea

Python analysis of class marks from a CSV file

The program reads marks from a CSV file and finds the mean, median, highest, lowest and pass percentage. It shows how code can analyse data that a spreadsheet also holds.

Make it yourself: 8 stepsGet a ready-made kit: Minor Projects

A drawing for computing and coding projects, not a photograph of this model.

What it shows

The program reads marks from a CSV file and finds the mean, median, highest, lowest and pass percentage. It shows how code can analyse data that a spreadsheet also holds.

The science

CSV is plain text with values separated by commas, readable by Python and spreadsheets. The csv module splits each line into fields. The statistics module gives the mean (average), median (middle value) and mode. A gap between mean and median tells you if a few very high or low marks pull the average.

Materials

Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.

  • A computer, laptop or phone with a browser (free)
  • Python 3 with IDLE, or the free Thonny editor, or an online Python runner (all free)
  • A CSV file marks.csv made in Notepad or a spreadsheet with a header name,maths and about 20 made-up students
  • A notebook and a pencil

Safety

Read before you start

This project uses safe, everyday materials. Still, read the rules below with a parent before you start.

Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.

All the safety rules

Step by step

8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.

  1. In Notepad write the first line name,maths and then 20 lines such as Asha,72 and save as marks.csv in the same folder as your program (use made-up names).

  2. Create analyse.py with import csv and import statistics on the first lines.

  3. Open the file: marks = [] then with open("marks.csv") as f: and reader = csv.DictReader(f).

  4. Inside the with, add for row in reader: marks.append(int(row["maths"])).

  5. Print the count with print("Students:", len(marks)) and the mean with print("Mean:", round(statistics.mean(marks), 1)).

  6. Print the median with statistics.median(marks), the highest with max(marks) and the lowest with min(marks).

  7. Count passes with passed = len([m for m in marks if m >= 33]) and print the percentage with round(passed * 100 / len(marks), 1).

  8. Compare the numbers with the same calculations in a spreadsheet using AVERAGE, MEDIAN, MAX and MIN.

What you should see

Expected result

The program prints the number of students, mean, median, highest, lowest and pass percentage. These agree with the spreadsheet values, which gives good confidence that both are correct.

Viva questions

A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.

01What is a CSV file?

A text file where each line is a row and commas separate the columns.

02What is the difference between mean and median?

The mean is the average; the median is the middle value when sorted.

03Why convert with int()?

The csv module reads everything as text.

04What does DictReader do?

It reads each row as a dictionary using the header names as keys.

Free ebook: Viva Questions for Science Projects

Take it further

Make it your own

Add a second subject column and print the student with the best total, and draw a bar of stars for each mark range.

Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.

Free ebooks for this project

Find out more about computing and coding

Free, well-known places to explore the subject further. Ask a grown-up before you sign up for anything or type your name anywhere.

WhatsApp us