Agent Skills
› kinncj/Heimdall
› jupyter-patterns
jupyter-patterns
GitHub提供Jupyter Notebook最佳实践,规范单元格顺序(从设置到结论),支持通过Papermill参数化执行和nbformat编程创建。涵盖导出、Git清理输出及确保可复现性的规则,适用于.ipynb文件处理。
Trigger Scenarios
处理 .ipynb 文件
优化 Jupyter Notebook 结构
配置 Papermill 参数化执行
使用 nbformat 创建笔记本
执行 notebook 导出或清理
Install
npx skills add kinncj/Heimdall --skill jupyter-patterns -g -y
SKILL.md
Frontmatter
{
"name": "jupyter-patterns",
"description": "Apply best practices for Jupyter notebooks: cell ordering, reproducibility, parameterisation. Use when working with .ipynb files."
}
SKILL: Jupyter Notebook Patterns
Notebook Structure
Cells should follow this order:
- Setup — imports, configuration, constants
- Data Loading — load raw data with validation
- EDA — exploratory data analysis, distributions, correlations
- Preprocessing — cleaning, feature engineering
- Modeling — model training and evaluation
- Visualization — charts and figures
- Conclusions — findings summary, next steps
Parameterized Execution with Papermill
# In notebook cell tagged with "parameters":
# Click: View -> Cell Toolbar -> Tags -> add "parameters" tag
dataset = "data/train.csv" # papermill will override this
output_dir = "outputs"
n_estimators = 100
random_state = 42
# Execute with papermill
papermill input.ipynb output.ipynb \
-p dataset "data/test.csv" \
-p n_estimators 200 \
-p random_state 0
Programmatic Notebook Creation
import nbformat as nbf
nb = nbf.v4.new_notebook()
nb.cells = [
nbf.v4.new_markdown_cell("# Analysis: {Title}"),
nbf.v4.new_code_cell("import pandas as pd\nimport numpy as np"),
nbf.v4.new_code_cell("df = pd.read_csv('data.csv')\ndf.head()"),
]
with open('analysis.ipynb', 'w') as f:
nbf.write(nb, f)
Export
# To HTML (with outputs)
jupyter nbconvert --to html --execute notebook.ipynb
# To PDF
jupyter nbconvert --to pdf --execute notebook.ipynb
# Execute in place
jupyter nbconvert --to notebook --execute --inplace notebook.ipynb
Git Hygiene
# Clear outputs before commit
jupyter nbconvert --to notebook --ClearOutputPreprocessor.enabled=True \
--inplace notebook.ipynb
# Or use nbstripout (installs as git filter)
pip install nbstripout
nbstripout --install
Rules
- Restart kernel and run all cells before committing.
- Clear all outputs before git commit.
- Tag parameter cells for papermill.
- Each notebook should be self-contained and reproducible.
- Include
random_stateparameter for reproducibility. - Use relative paths for data files.
Version History
- f4ea31f Current 2026-07-05 10:42


