Thuta Learning
ProjectsData & Databasesintermediate

Student Score Project - Part 2: Analysis

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Apply Student Score Project - Part 2: Analysis in a hands-on project
  • Write and run the code yourself
  • Build out an entire project step by step

Take a moment to think about this

In this step, we'll add real analysis features to the scores array we built in Part 1. Using aggregation functions like np.mean(), np.max(), and np.min() together with the axis parameter, we'll compute each student's average (axis=1) and each subject's class average (axis=0). Then we'll use broadcasting to apply a curve (a grade adjustment giving different bonus points per subject) in one shot, without writing a loop. This pattern shows up constantly in real data analysis code, and it feeds directly into Part 3's final report.

Let's build it

Use scores.mean(axis=1) to compute each student's average score array. Use scores.mean(axis=0) to compute each subject's class average. Use np.argmax(student_avg) to find the index of the student with the highest average. Create a bonus array with different values per subject (curve = [2, 5, 0, 3]), add it to scores via broadcasting (curved_scores = scores + curve), and compare the result against the original scores.

Example Code

python
import numpy as np

students = ["Aye", "Bo", "Cho", "Dan", "Eaint"]
subjects = ["Math", "Myanmar", "English", "Science"]

scores = np.array([
    [78, 85, 90, 72],
    [64, 70, 58, 80],
    [95, 88, 92, 91],
    [50, 60, 55, 48],
    [82, 79, 84, 88]
])

student_avg = scores.mean(axis=1)
subject_avg = scores.mean(axis=0)

print("student averages:", student_avg)
print("subject averages:", subject_avg)

top_index = np.argmax(student_avg)
print("top student:", students[top_index], student_avg[top_index])

# curve/bonus per subject: Math+2, Myanmar+5, English+0, Science+3
curve = np.array([2, 5, 0, 3])
curved_scores = scores + curve

print("before curve:\n", scores)
print("after curve:\n", curved_scores)
You should see
You'll see the student_avg and subject_avg arrays printed, along with the top student's name, and curved_scores showing the new scores with the curve value added per subject column.

Try it in 5 minutes

Try giving the curve array only 3 elements instead of the current 4 (matching the subjects list) and see the broadcasting error appear for yourself (5 minutes).

A quick word of caution

axis=1 collapses the values within a row (subjects), giving you student-wise results, while axis=0 collapses the values within a column (students), giving you subject-wise results — be careful not to mix up the direction.

Easy traps

  • Mixing up axis=0 (column-wise) and axis=1 (row-wise) and ending up with subject averages instead of student averages
  • Writing a curve array whose length doesn't match the column count of scores, triggering a broadcasting shape error

Try it yourself

Try giving the curve array only 3 elements instead of the current 4 (matching the subjects list) and see the broadcasting error appear for yourself (5 minutes).

You'll know it worked when: You'll see the student_avg and subject_avg arrays printed, along with the top student's name, and curved_scores showing the new scores with the curve value added per subject column.