Apply your knowledge to build something amazing!
:information_source: Project Overview Difficulty Level: Intermediate
Estimated Time: 2-3 hours
Skills Practiced:
- Data generation with Numpy
- Statistical calculations
- Data visualization with Matplotlib
- Working with arrays and tables
- Creating professional charts
What You'll Build: A complete exam results analysis system that generates student scores, calculates statistics, and creates visualizations to help understand class performance.
📝 Part 1: Data Setup (30 mins)
└─→ Import libraries
└─→ Store student data
└─→ Calculate totals & averages
└─→ Create score table
📊 Part 2: Line Graph Visualization (45 mins)
└─→ Plot student scores
└─→ Add labels and legends
└─→ Format the graph
└─→ Display results
📈 Part 3: Bar Chart Analysis (45 mins)
└─→ Calculate subject averages
└─→ Create bar visualization
└─→ Add statistical insights
└─→ Polish presentation
🎥 Part 4: Video Recording (30 mins)
└─→ Demonstrate code
└─→ Explain insights
└─→ Submit project
The project consists of:
Your project will be evaluated based on the following criteria:
Code Functionality (50%)
Code Quality (25%)
Creativity and Features (15%)
Video Submission (10%)
Final submission should include:
.py
or notebook)Make sure to double-check your project before submitting. Ensure you have included the Python code file and the video explanation as required.
:warning: Important Setup Instructions
- Click the link here
- Make a copy of the Colab Notebook into your Google Drive
- Rename your copy to include your name (e.g., "YourName_ExamAnalysis")
- Do NOT edit the original shared notebook!
import numpy as np
from prettytable import PrettyTable
import matplotlib.pyplot as plt
:bulb: Pro Tip Copy and paste this code to get started quickly! The data represents 7 students and their scores in 3 subjects.
students = np.array(["Adam", "Bob", "Crystal", "David", "Edmund", "Lily", "Jasmine"])
math_score = np.array([87, 42, 87, 99, 53, 95, 89])
science_score = np.array([78, 51, 89, 89, 70, 89, 90])
english_score = np.array([90, 66, 83, 83, 91, 90, 90])
Now let's calculate statistics for each student:
Calculate the total score by adding all three subject scores:
total = math_score + science_score + english_score
Calculate the average score and round to 2 decimal places:
average = np.round(total / 3, 2)
:memo: Expected Output When you print these arrays, you should see:
ini
Total score: [255 159 259 271 214 274 269] Average score of each student: [85. 53. 86.33 90.33 71.33 91.33 89.67]
:warning: Common Error If you get a "NameError", make sure you've run the previous cell that defines the score arrays!
Let's create a nicely formatted table to display all our data:
Create the table object:
score_table = PrettyTable()
Set up the table structure:
# Add field names (column headers)
score_table.field_names = np.append("Students", students)
# Add rows for each data type
score_table.add_row(np.append("Maths", math_score))
score_table.add_row(np.append("Sciences", science_score))
score_table.add_row(np.append("English", english_score))
score_table.add_row(np.append("Total", total))
score_table.add_row(np.append("Average", average))
Display the table:
print("Examination Score Table")
print(score_table)
:bulb: Understanding np.append() The
np.append()
function adds "Students" as the first element before all student names. This creates our row labels!
Expected Output:
Examination Score Table
Students | Adam | Bob | Crystal | David | Edmund | Lily | Jasmine |
---|---|---|---|---|---|---|---|
Maths | 87 | 42 | 87 | 99 | 53 | 95 | 89 |
Sciences | 78 | 51 | 89 | 89 | 70 | 89 | 90 |
English | 90 | 66 | 83 | 83 | 91 | 90 | 90 |
Total | 255 | 159 | 259 | 271 | 214 | 274 | 269 |
Average | 85.0 | 53.0 | 86.33 | 90.33 | 71.33 | 91.33 | 89.67 |
:white_check_mark: Milestone Checkpoint 1: If you can see the formatted table with all scores, totals, and averages - great job! You've completed Part 1! :tada:
Now let's create a line graph to visualize how each student performs across different subjects.
Create three lines, one for each subject:
# Plot lines for each subject
plt.plot(students, math_score)
plt.plot(students, science_score)
plt.plot(students, english_score)
:memo: What's Happening?
- x-axis: Student names
- y-axis: Scores (0-100)
- Each line represents a different subject
Make your graph professional by adding descriptive labels:
plt.title("Examination Score Graph", fontsize=16, fontweight='bold')
plt.xlabel("Students", fontsize=12)
plt.ylabel("Score", fontsize=12)
Help readers understand which line represents which subject:
plt.legend(["Mathematics", "Science", "English"])
:bulb: Making It Look Better Add this line to improve readability:
python
plt.grid(True, alpha=0.3) # Adds a light grid
plt.show()
:warning: Debugging Tips Graph not showing?
- Make sure you're running cells in order
- Check that all variables are defined
- Try
plt.figure()
before plotting to create a new figureLines look weird?
- Verify your data arrays have the same length
- Check for any typos in variable names
:white_check_mark: Milestone Checkpoint 2: Your line graph should show all three subjects with proper labels. Bob's low scores should be clearly visible! :chart_with_downwards_trend:
Let's analyze which subject has the highest class average!
from scipy import stats
Calculate the mean score for each subject:
# Calculate means and round to 2 decimal places
mean_math = round(stats.mean(math_score), 2)
mean_sc = round(stats.mean(science_score), 2)
mean_eng = round(stats.mean(english_score), 2)
# Print to verify
print(f"Mean for Math: {mean_math}")
print(f"Mean for Science: {mean_sc}")
print(f"Mean for English: {mean_eng}")
:memo: Expected Output
rust
Mean for Math: 78.86 Mean for Science: 79.43 Mean for English: 84.71
Organize your data for visualization:
# Subject names for x-axis
subjects = ["Mathematics", "Science", "English"]
# Average scores for y-axis
mean_subjects = [mean_math, mean_sc, mean_eng]
# Create a new figure
plt.figure(figsize=(8, 6))
# Create bar chart with colors
colors = ['#FF6B6B', '#4ECDC4', '#45B7D1']
plt.bar(subjects, mean_subjects, color=colors)
# Add title and labels
plt.title("Average Score by Subject", fontsize=16, fontweight='bold')
plt.xlabel("Subjects", fontsize=12)
plt.ylabel("Average Score", fontsize=12)
# Add value labels on top of bars
for i, v in enumerate(mean_subjects):
plt.text(i, v + 1, str(v), ha='center', fontweight='bold')
# Add a horizontal line for overall average
overall_avg = sum(mean_subjects) / len(mean_subjects)
plt.axhline(y=overall_avg, color='red', linestyle='--', alpha=0.7, label=f'Overall Avg: {overall_avg:.2f}')
plt.legend()
# Display the chart
plt.show()
:bulb: Best Practice Adding value labels on bars makes it easier to read exact values without referring to the y-axis!
:white_check_mark: Milestone Checkpoint 3: Your bar chart should clearly show that English has the highest average score! :books:
:bulb: Using AI for Data Visualization Try these prompts to enhance your project:
Basic Prompts:
- "Help me generate a scatter plot in Matplotlib to visualize the relationship between study hours and exam scores."
- "Create a pie chart showing the grade distribution (A, B, C, D, F) based on average scores"
- "Add error bars to my bar chart to show standard deviation"
Advanced Prompts:
- "Create a heatmap showing correlation between different subjects"
- "Generate a box plot to identify outliers in the score data"
- "Create an animated bar chart that shows scores changing over time"
Ready to go beyond the basics? Try these challenges:
Create a pie chart showing how many students got A (90+), B (80-89), C (70-79), D (60-69), or F (<60) based on their average scores.
Create a complete dashboard with:
:warning: Troubleshooting Guide Error: "NameError: name 'plt' is not defined"
- Solution: Make sure you've imported matplotlib.pyplot as plt
Error: "ValueError: x and y must have same first dimension"
- Solution: Check that your arrays have the same length (7 students)
Error: Table not displaying properly
- Solution: Ensure PrettyTable is imported and you're using print() to display
Error: Graph overlapping or cut off
- Solution: Use
plt.figure(figsize=(10, 6))
before plotting- Add
plt.tight_layout()
beforeplt.show()
Error: "ModuleNotFoundError: No module named 'scipy'"
- Solution: Install scipy using
!pip install scipy
in Colab
:information_source: Video Guidelines For your 2-3 minute video:
Introduction (30 seconds)
Code Walkthrough (1 minute)
Insights (1 minute)
Conclusion (30 seconds)
Recording Tips:
Before submitting, ensure you have:
Good luck with your exam analysis project! Remember, data tells a story - make yours compelling! :bar_chart::sparkles: