A script that loads your sales data, generates a pandas summary, feeds it to Claude, and prints a written analysis — including identified trends, anomalies, and actionable recommendations. Runs in under 10 seconds.
Get Your Anthropic API Key
Go to console.anthropic.com, sign up for free, and create an API key. New accounts get free credits — more than enough for this course.
Install the SDK:
$ pip install anthropic
Store your key in an environment variable — never hardcode it in your script:
# Mac/Linux — add to ~/.zshrc or ~/.bashrc
export ANTHROPIC_API_KEY="sk-ant-..."
# Windows PowerShell
$env:ANTHROPIC_API_KEY="sk-ant-..."
Feed Spreadsheet Data to Claude
import pandas as pd
import anthropic
df = pd.read_csv("sales.csv")
# Generate a summary with pandas
by_region = df.groupby("region")["revenue"].agg(["sum","mean","count"])
monthly = df.groupby("month")["revenue"].sum()
top_reps = df.groupby("rep")["revenue"].sum().nlargest(5)
# Build the prompt
prompt = f"""Analyze this sales data and provide:
1. Key trends you notice
2. Any anomalies or concerns
3. Top 3 actionable recommendations
Regional summary:
{by_region.to_string()}
Monthly revenue:
{monthly.to_string()}
Top 5 reps:
{top_reps.to_string()}
Be specific. Reference actual numbers."""
# Call Claude
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": prompt}]
)
analysis = response.content[0].text
print(analysis)
# Save to file
with open("analysis.txt", "w") as f:
f.write(analysis)
The key insight: Claude doesn't need to "see" your spreadsheet. You use pandas to extract the relevant numbers, format them clearly, and send that text to Claude. The analysis is just as good — and you control exactly what data gets sent.
Structured Prompts Get Better Analysis
def analyze_data(df, context=""):
"""Analyze a DataFrame with Claude."""
stats = {
"total_rows": len(df),
"date_range": f"{df['date'].min()} to {df['date'].max()}",
"total_revenue": f"${df['revenue'].sum():,.0f}",
"avg_deal": f"${df['revenue'].mean():,.0f}"
}
prompt = f"""You are a senior data analyst reviewing sales performance.
Context: {context}
Dataset overview:
- Total records: {stats['total_rows']}
- Period: {stats['date_range']}
- Total revenue: {stats['total_revenue']}
- Average deal size: {stats['avg_deal']}
Detailed breakdown:
{df.groupby('region')['revenue'].describe().to_string()}
Provide analysis in exactly this format:
## Executive Summary (2-3 sentences)
## Key Findings (bullet points with specific numbers)
## Red Flags (if any)
## Recommendations (3 specific, actionable items)"""
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=1500,
messages=[{"role": "user", "content": prompt}]
)
return response.content[0].text
# Use it
df = pd.read_csv("sales.csv")
analysis = analyze_data(df, context="Q4 2024 sales data, US regions")
print(analysis)
Day 4 Complete
- Anthropic API key configured and SDK installed
- Fed pandas DataFrame summaries to Claude
- Got structured written analysis from your own data
- Built a reusable
analyze_data()function
Tomorrow: Build the Automated Report
Day 5 combines everything into a fully automated reporting system that runs on a schedule and replaces 10 hours of weekly Excel work.
Day 5: Final Project