Open In Colab

Homework 2: Pandas Introduction#

Complete all exercises below. Show your work and include comments explaining your approach.

! curl -LsSf https://astral.sh/uv/install.sh | sh && \
  uv pip install -q --system "s26-06642 @ git+https://github.com/jkitchin/s26-06642.git"
from pycse.colab import pdf
downloading uv 0.10.3 x86_64-unknown-linux-gnu
no checksums to verify
installing to /home/runner/.local/bin
  uv
  uvx
everything's installed!
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

Problem 1: DataFrame Basics#

Load and explore experiment data from a catalytic reactor study.

# Load experiment dataset from URL
url = "https://raw.githubusercontent.com/jkitchin/s26-06642/main/dsmles/data/hw02_experiments.csv"
experiments = pd.read_csv(url)

print(f"Loaded {len(experiments)} experiments")
experiments.head(10)
Loaded 50 experiments
exp_id temperature pressure catalyst conversion selectivity
0 EXP001 400 8.1 Ni 0.567 0.895
1 EXP002 450 2.8 Ni 0.791 0.921
2 EXP003 300 5.6 Pt 0.449 0.769
3 EXP004 400 6.3 Ni 0.350 0.911
4 EXP005 400 1.4 Pt 0.488 0.807
5 EXP006 450 6.5 Pd NaN 0.883
6 EXP007 300 2.5 Ni 0.904 0.884
7 EXP008 300 1.6 Pd 0.825 0.855
8 EXP009 400 9.5 Pt 0.712 0.726
9 EXP010 350 9.7 Ni 0.866 0.942

1a. How many experiments are missing conversion data? Which experiment IDs are missing this data?

# Your code here

1b. Use .describe() to get summary statistics for the numeric columns. What is the median pressure?

# Your code here

1c. Filter the DataFrame to show only experiments using Pt catalyst with temperature >= 400 K.

# Your code here

Problem 2: Data Manipulation#

Continue working with the experiments DataFrame.

2a. Calculate the average conversion and selectivity for each catalyst type using .groupby().

# Your code here

2b. Add a new column called ‘yield’ calculated as conversion × selectivity.

# Your code here

2c. Find the top 5 experiments by yield. Display exp_id, catalyst, temperature, and yield.

# Your code here

2d. What is the average yield for each combination of catalyst and temperature? Use .groupby() with multiple columns.

# Your code here

Problem 3: Visualization#

Create visualizations to explore the data.

3a. Create a scatter plot of conversion vs temperature, colored by catalyst type.

Hint: You can loop through catalyst types and plot each separately with different colors, or use pandas plotting.

# Your code here

3b. Create a box plot comparing conversion distributions across different catalysts.

Hint: Use df.boxplot(column='conversion', by='catalyst') or matplotlib.

# Your code here

3c. Based on your analysis, which catalyst and temperature combination would you recommend for maximizing yield? Justify your answer with specific numbers from your analysis.

Your answer here: