Lesson 6.1: Data Mini-Projects – Introduction

Today’s Goals

  • Start working with real-world data using Python
  • Learn about data structures for data storage
  • Introduce file handling for reading datasets

Warm-Up Question

  • What kind of data would be fun to explore? (Sports, movies, etc.)

Understanding Data

  • Data can come in many forms: lists, dictionaries, CSV files
  • Python's data structures are perfect for storing and manipulating it

Simple Dataset Example

# Sample data: List of students and their scores
students = [
    {'name': 'Alice', 'score': 90},
    {'name': 'Bob', 'score': 80},
    {'name': 'Charlie', 'score': 85}
]

# Finding average score
total_score = sum([student['score'] for student in students])
avg_score = total_score / len(students)
print("Average Score:", avg_score)

Key Concepts for Today

  • List of dictionaries is a useful format for structured data
  • We'll manipulate this data using loops and conditionals

Class Practice

  • How would you find the highest score?
  • Write the code for it

Working with CSV Files

import csv

# Open and read CSV file
with open('students.csv', mode='r') as file:
    reader = csv.DictReader(file)
    for row in reader:
        print(row)

Class Activity

  • Explore CSV files with your own sample dataset
  • Print the data from the file and analyze it

Student Challenge

  • Use a real-world dataset (movies, sports scores, etc.)
  • Perform basic data analysis (averages, maximums, etc.)

Wrap-Up

  • Data exploration with Python is powerful
  • Next time: We'll dive into more complex datasets and data manipulation techniques