Module 02: Pandas Introduction - Participation Exercises#
Exercise 2.1: Prediction - Data Types#
Type: 🔮 Prediction (3 min)
You receive a CSV file with experimental data. Before loading it, predict what data types pandas will assign:
# Imagine this CSV content:
csv_content = """
experiment_id,temperature,pressure,catalyst,yield,date,notes
EXP001,350.5,1.2,Pt/Al2O3,78.3,2024-01-15,Good run
EXP002,375.0,1.5,Pd/C,82.1,2024-01-16,
EXP003,400.0,1.8,Pt/Al2O3,NaN,2024-01-17,Equipment failure
"""
# Predict the dtype for each column:
# experiment_id: ???
# temperature: ???
# pressure: ???
# catalyst: ???
# yield: ???
# date: ???
# notes: ???
Your dtype predictions:
Column |
Predicted dtype |
Reasoning |
|---|---|---|
experiment_id |
||
temperature |
||
pressure |
||
catalyst |
||
yield |
||
date |
||
notes |
Exercise 2.2: Mini-Exercise - Data Exploration Race#
Type: 🔧 Mini-Exercise (7 min)
Load the dataset below and answer all questions as quickly as possible. First person done raises their hand!
import pandas as pd
import numpy as np
# Create sample reactor data
np.random.seed(42)
n = 100
df = pd.DataFrame({
'reactor': np.random.choice(['R1', 'R2', 'R3'], n),
'temperature': np.random.uniform(300, 500, n),
'pressure': np.random.uniform(1, 10, n),
'conversion': np.random.uniform(0.3, 0.95, n),
'shift': np.random.choice(['Day', 'Night'], n)
})
df.loc[np.random.choice(n, 5), 'conversion'] = np.nan # Add some missing values
# QUESTIONS - Answer using pandas operations:
# 1. How many rows and columns?
# 2. How many missing values in 'conversion'?
# 3. What is the mean temperature for reactor R2?
# 4. How many experiments were run on the Night shift?
# 5. What is the maximum conversion?
# Your code here:
Exercise 2.3: Discussion - Missing Data Strategies#
Type: 💬 Discussion (5 min)
You have sensor data from a reactor with 10% missing values. Discuss with a partner:
What are three different ways to handle the missing data?
What are the pros and cons of each approach?
Does it matter why the data is missing?
Scenario: The missing values occur mostly during shift changes. How does this affect your strategy?
Discussion notes:
Strategy |
Pros |
Cons |
|---|---|---|