End Activity Session (Day 3)
A cartoon panda looking over a yearβs worth of monthly class exams. The panda is doing great; A+! (Midjourney5)[https://www.midjourney.com/jobs/6b63c3ca-c64d-41b8-a791-7e4b2594c781?index=0]
Introduction
In this end-of-day activity, weβll practice the concepts you learned today: control flows and pandas Series analysis. Weβll work with real student test score data to apply if/else statements, loops, and Series operations that you learned in todayβs sessions.
Learning Objectives
By completing this exercise, you will practice:
- Control Flow Concepts (from Sessions 3a & 3b):
- Using
if
/elif
/else
statements for decision making - Using
for
loops to iterate through data - Combining control flows with data analysis
- Using
- Series Operations (from Session 3c):
- Creating Pandas Series with custom indices
- Using Series statistical methods (
.mean()
,.median()
,.max()
,.min()
) - Basic Series indexing and slicing
- Applying NumPy statistical functions to Series
Setup
Task 0.1: Import the necessary libraries
Import the pandas and numpy libraries that you learned about today.
Part 1: Creating and Analyzing Test Scores
Weβll work with monthly test scores for a student throughout the academic year.
Task 1.1: Create the Test Scores Series
Create a pandas Series using the following data: - Scores: [78, 85, 92, 88, 79, 83, 91, 87, 89, 94]
- Months: ['Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
Create a Series called scores
where the months are the index and the scores are the values.
Task 1.2: Display the Series
Print your scores
Series to see the data structure.
Task 2: Basic Statistical Analysis
Use the Series methods you learned today to calculate and print the following statistics:
- Average score (using
.mean()
) - Highest score (using
.max()
)
- Lowest score (using
.min()
) - Median score (using
.median()
)
Remember to use f-string formatting to make your output readable! For example: f"Average score: {average_score:.2f}"
Part 2: Applying Control Flows
Task 3: Performance Categories
Use if
/elif
/else
statements to categorize the overall performance based on the average score:
- If average β₯ 90: βExcellentβ
- If average β₯ 80: βGoodβ
- If average β₯ 70: βSatisfactoryβ
- Otherwise: βNeeds Improvementβ
Create a variable called performance
and print the result with the average score.
For example, if the average score is 95, then you want your code to print:
Overall performance: Excellent (Average: 95.00)
Task 4: Finding Best and Worst Months
Use Series indexing to find: 1. The month with the highest score (hint: use .idxmax()
) 2. The month with the lowest score (hint: use .idxmin()
)
Print the results in a clear format.
Conclusion
Excellent work! In just four focused tasks, you practiced the key concepts from Day 3:
β
Pandas Series Fundamentals: - Created a Series with custom indices - Used statistical methods (.mean()
, .max()
, .min()
, .median()
) - Applied Series indexing methods (.idxmax()
, .idxmin()
)
β
Control Flow Application: - Used if
/elif
/else
statements for data categorization - Combined conditional logic with data analysis
These core skills form the foundation for more advanced data analysis!
Reflection Questions
- How did using Series methods compare to working with regular Python lists?
- What other types of data could you analyze using these same techniques?
- Which part of the exercise felt most challenging?
Optional Extension
If you finish early: Create your own Series with 5-7 data points (maybe daily temperatures for a week, or your favorite restaurant ratings) and apply the same analysis techniques you used today.