Home

Use Claude Code for Python in VS Code on Mac

You’ve set up Python in VS Code and can write code manually. Now you want AI to help write, improve, and debug your Python code while you focus on the analysis. Think of Claude Code as a coding partner who lives inside VS Code - you describe what you want, and it writes or improves the code while you stay in the same window.

Key Concepts

What You’ll Need

Step 1: Open VS Code and Create Python Project

Step 2: Install and Sign in to Claude Code Extension

Step 3: Create Initial Python Script Manually

from sklearn import datasets
import pandas as pd

# Load iris dataset
iris = datasets.load_iris()
iris_df = pd.DataFrame(iris.data, columns=iris.feature_names)
iris_df['species'] = iris.target_names[iris.target]

# Display structure
print(iris_df.info())
print("\nSummary statistics:")
print(iris_df.describe())

Step 4: Ask Claude to Add Scatter Plot

Add code to iris_analysis.py to create a scatter plot of sepal length vs. width, colored by species. Use seaborn.

Step 5: Run the Updated Code

Step 6: Ask Claude to Refine Plot

Remove title. Change marker type by species. Change to the whitegrid style.

Step 7: Ask Claude for PCA Analysis

Add code to perform PCA on the numeric variables and plot the samples using the first two principal components.

Step 8: Ask Claude to Review and Comment

Review the entire script for correctness. Add comments when necessary.

Next Steps

Troubleshooting

Workflow Summary


Created by Steven Ge on December 11, 2025.