Skip to content

project rulesData and AIpythonpandas

Python Data Science Rules

Project rules for Python data science repos: notebooks kept thin, logic in modules, fixed seeds, tidy pandas code and versioned data.

npx workspacetemplates add python-data-science-rules --tool claude-code

Writes 1 file to your project root

CLAUDE.mdadd to your file21 lines · 1.3 KBFile
# Project rules: Python data science

## Layout
- Put reusable code in a package under `src/` with tests in `tests/`. Notebooks go in `notebooks/`, numbered, and only import from the package. Strip outputs before commit with `nbstripout`.
- Never copy functions between notebooks. Move them into a module the moment a second notebook needs them.

## Reproducibility
- Pin the environment with `pyproject.toml` and a lock file (uv or pip-tools). Record the Python version.
- Set seeds in one place for `random`, NumPy and any model library, and pass a `random_state` to splitters and estimators.
- Keep raw data read-only. Version data and models with DVC or an equivalent, and commit only the pointer files. Never commit credentials or personal data.

## Pandas style
- Prefer vectorized operations and method chaining with `.assign`, `.query` and `.pipe`. Do not loop over rows or modify a frame in place.
- Be explicit: set dtypes on load, name columns in snake_case, use `merge(..., validate=...)` and assert row counts after joins.
- Avoid `SettingWithCopyWarning` by working on copies deliberately.

## Evaluation
- Split before any fitting or scaling to avoid leakage. Report metrics with the split, seed and data version.

## Checks
- Run `ruff check`, `ruff format` and `pytest`. Tests cover transform functions with small hand-made frames.

What it does

Data science repos drift into notebooks nobody can rerun. These rules push reusable logic into a package, keep notebooks for exploration and reporting, and make each result traceable to code, data and a seed.

They also say how to write pandas without hidden mutation, pin environments, and keep large data out of git.

Example

you › Clean the sales export and add a monthly revenue feature

agent › The agent writes a typed function in src/sales/features.py, loads with explicit dtypes, validates the join, adds a pytest case with a three-row frame and calls it from a numbered notebook.

Questions

Should notebooks be banned?
No. They are good for exploring and presenting. The rule is only that real logic does not live in them.
Which data versioning tool is required?
None in particular. DVC is named as an example; any tool that keeps data out of git and records versions works.
  • LLM App Rules

    Project rulespython

    Free
  • PyTorch Rules

    Project rulespython

    Free
  • Data Pipeline Design

    SkillData and AI

    Free