首页

在 Mac 的 VS Code 中使用 Claude Code 进行 Python 开发

你已在 VS Code 中设置好 Python 环境,可以手动编写代码。现在你想让 AI 帮助编写、改进和调试 Python 代码,以便专注于分析工作。可以把 Claude Code 想象成住在 VS Code 里的编程伙伴——你描述需求,它编写或改进代码,而你始终在同一窗口中工作。

核心概念

准备工作

步骤 1:打开 VS Code 并创建 Python 项目

步骤 2:安装并登录 Claude Code Extension

步骤 3:手动创建初始 Python 脚本

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())

步骤 4:让 Claude 添加散点图

在 iris_analysis.py 中添加代码,创建萼片长度与宽度的散点图,按物种着色。使用 seaborn。

步骤 5:运行更新后的代码

步骤 6:让 Claude 优化图表

移除标题。按物种更改标记类型。更改为 whitegrid 样式。

步骤 7:让 Claude 进行 PCA 分析

添加代码对数值变量进行 PCA 分析,并使用前两个主成分绘制样本图。

步骤 8:让 Claude 审查并添加注释

检查整个脚本的正确性。必要时添加注释。

下一步

故障排除

工作流程总结


Steven Ge 创建于 2025 年 12 月 11 日。