name: refactor_nb description: Jupyter Notebook (.ipynb) 内のコード要素を一括置換・リファクタリングする
refactor_notebooks Skill
This skill is for programmatically analyzing Jupyter Notebook (.ipynb) files and performing batch replacement or modification of specific import patterns or code blocks.
Instructions
-
Analyze Notebook Structure:
- Load
.ipynbfiles as JSON using Python and iterate through thecellslist. - Verify if the
cell_typeof each cell iscode.
- Load
-
Filter and Match:
- Join the
sourcefield (list format) into a string and use regular expressions or keyword matching to identify target cells. - Target specific import statements (e.g.,
from gwexpy.noise import asd), function calls, or targeted comments.
- Join the
-
Implement Transformation:
- Create a transformation script to rewrite the
sourcelist of the cells in memory. - The updated source must be in list format (each element as a string ending with a newline).
- Create a transformation script to rewrite the
-
Write and Verify:
- Save the file using
json.dump, maintaining an indent of 1 (agwexpyconvention) and specifyingensure_ascii=False. - Verify that the resulting notebook is valid JSON and that the intended changes have been applied using
view_fileor similar.
- Save the file using
Usage Guidelines
- When modifying multiple notebooks across a directory, create a loop script that collects
.ipynbfiles usingglobor similar. - For complex refactoring, adopt a workflow of saving the logic as a temporary
.pyscript, executing it viarun_command, and then deleting the script.
Related skills
Next.js App Router Expert
Development
A skill that turns Claude into a Next.js App Router expert.
Claude CodeCursoradvanced
890
234
2,619
README Generator
Development
Creates professional and comprehensive README.md files for your projects.
claudeCursorWindsurfbeginner
259
72
589
API Documentation Writer
Development
Generates comprehensive API documentation in OpenAPI/Swagger format.
claudeCursorWindsurfintermediate
156
44
451