Student Marks Analysis Project Using NumPy
In this practical project, we will build a student marks analysis system using NumPy. We will store student marks in arrays, calculate totals and averages, identify the highest and lowest marks, assign grades, check pass or fail status, rank students, and save the results to files. This project demonstrates how NumPy simplifies numerical analysis in real-world applications.
1. Project Objectives
After completing this project, you will be able to:
- Create NumPy arrays for student names, subjects, and marks.
- Calculate total marks and average marks for each student.
- Find subject-wise averages and highest and lowest scores.
- Apply conditions to identify passing and failing students.
- Assign grades based on average marks.
- Sort students according to their performance.
- Export analysis results to a CSV file.
- Save and reload numerical data using the NPZ format.
2. Project Requirements
Our institute, CIIT TRANING INSTITUTE, wants to analyze the marks of three students across three subjects: Python, NumPy, and Statistics.
| Student | Python | NumPy | Statistics |
|---|---|---|---|
| Samadhan | 85 | 90 | 78 |
| Pradnya | 72 | 88 | 91 |
| Samiksha | 34 | 65 | 55 |
3. Import NumPy and Create the Dataset
First, import NumPy. Store the student names and subject names separately from the numerical marks. The marks will be represented by a two-dimensional array.
Expected Output
Each row of marks represents one student, and each column represents
one subject. Therefore, the first row contains Samadhan's marks and the first
column contains every student's Python marks.
4. Understand the Array Structure
Expected Output
The shape (3, 3) means the array contains three rows and three columns.
There are nine individual marks in total.
5. Calculate Total and Average Marks
Use np.sum() to calculate totals and np.mean() to calculate
averages. The parameter axis=1 performs calculations across each row,
producing one result per student.
Expected Output
| Student | Total Marks | Average |
|---|---|---|
| Samadhan | 253 / 300 | 84.33 |
| Pradnya | 251 / 300 | 83.67 |
| Samiksha | 154 / 300 | 51.33 |
axis=1 calculates across columns within each
row. axis=0 calculates down the rows, giving one result per subject.
6. Find Highest and Lowest Marks for Each Student
The functions np.max() and np.min() can find the highest
and lowest score in each student's row.
Expected Output
Samadhan's highest mark is 90, Pradnya's is 91, and Samiksha's is 65. Samiksha's lowest mark is 34, which is below the passing requirement of 35.
7. Perform Subject-Wise Analysis
To calculate results for each subject, use axis=0. NumPy then calculates
the mean, maximum, and minimum across all students for each subject.
Expected Output
| Subject | Average | Highest | Lowest |
|---|---|---|---|
| Python | 63.67 | 85 | 34 |
| NumPy | 81.00 | 90 | 65 |
| Statistics | 74.67 | 91 | 55 |
8. Check Pass and Fail Status
A student passes only when every subject mark is at least 35. The expression
marks >= 35 creates a Boolean array. Use np.all() with
axis=1 to check every subject for each student.
Expected Output
9. Assign Grades Using Conditions
We will assign grades according to the following illustrative rules. These are project-specific rules and may differ from your institute's official grading policy.
| Average Marks | Grade |
|---|---|
| 90 and above | A+ |
| 80 to less than 90 | A |
| 70 to less than 80 | B |
| 60 to less than 70 | C |
| 50 to less than 60 | D |
| Below 50 | F |
Expected Output
Notice that grade and pass/fail status are different calculations. Under the illustrative grading rules, Samiksha receives grade D but still fails the project because she scored below 35 in one subject.
10. Rank Students by Average Marks
Use np.argsort() to obtain the indices that sort average marks in
ascending order. Reverse the result to display the highest average first.
Expected Output
np.argsort() returns positions, not the
sorted student names. Use those positions to retrieve the corresponding names and
averages.
11. Find the Top Student and Class Average
NumPy can identify the student with the highest average and calculate the overall average across all individual marks.
Expected Output
The overall class average is the mean of all nine subject marks. Since every student has the same number of subjects, it is also equal to the mean of the three student averages.
12. Export Results to a CSV File
NumPy is useful for the calculations, while Python's built-in csv module
is convenient for exporting a mixture of text and numerical values.
Expected Output
The file student_marks_report.csv is created in the program's current
working directory. You can open it using a text editor or spreadsheet application.
13. Save and Load Data Using NPZ
The NPZ format stores multiple NumPy arrays in one compressed archive. It is useful when you want to save the original dataset and calculated results for later analysis.
Expected Output
np.save() for a single array, np.savez()
for multiple arrays in an archive, and np.savez_compressed() when you
also want compression.
14. Complete Project Code
The following script combines the key calculations, grading, ranking, CSV export, and NPZ persistence into one runnable program.
Run the complete script in your Python environment. It prints the report and creates
student_marks_report.csv and student_marks_data.npz in the
current working directory.
15. Common Mistakes
Mistake 1: Using the wrong axis
Using axis=0 for student totals calculates subject-wise totals instead.
Use axis=1 when you need one result per student.
Mistake 2: Checking only the average for passing
A student may have a passing average but still fail one subject. Use
np.all(marks >= 35, axis=1) to enforce the rule that every subject
must meet the minimum.
Mistake 3: Mixing up names and sorted indices
np.argsort() returns indices. Use those indices to access the
corresponding names and averages rather than treating the indices as marks.
Mistake 4: Trying to export mixed data as a purely numeric array
Student names and grades are text, while marks and averages are numerical. A CSV writer handles these different data types naturally.
Mistake 5: Forgetting to close a saved archive
Use with np.load(...) when reading NPZ files so the archive is closed
automatically after the data has been read.
16. Practice Exercises
- Add a fourth student and update the marks array.
- Calculate the percentage for every student.
- Find the subject with the highest class average.
- Count how many students passed and how many failed.
- Display only students whose average is greater than 80.
- Find the difference between the highest and lowest mark in each subject.
- Change the passing threshold to 40 and recalculate the results.
- Load the NPZ archive and display the saved subject names.
Summary
In this project, you used NumPy arrays to organize student marks and calculate totals, averages, highest and lowest marks, subject-wise statistics, grades, pass/fail status, and student rankings. You also used Boolean conditions and axis-based operations to analyze the dataset efficiently.
Finally, you exported the report to CSV and saved numerical data in compressed NPZ format. These techniques provide a foundation for larger data-analysis projects involving student results, sales records, and other numerical datasets.