ludo-technologies/python-best-practices/data-science

Claude Code and agent skill by ludo-technologies/python-best-practices

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

NumPy and pandas best practices for data science and ML code covering vectorization, DataFrame indexing and mutation under Copy-on-Write, dtypes, schema validation with pandera, reproducible randomness, transformation style, array typing, and numeric testing. Use when writing, reviewing, or refactoring code that uses numpy, pandas, DataFrames, ndarrays, Jupyter notebooks, or data pipelines, or when the user asks about pandas/numpy performance or idioms.

Install

npx vskill@latest install ludo-technologies/python-best-practices/data-science

SKILL.md

Python Data Science

NumPy and pandas best practices for data science and ML code. Designed for AI agents and LLMs to write fast, correct, and reproducible numeric code.

Numeric code has idioms that differ from general Python: loops are the anti-pattern, data structures are immutable buffers, and dtypes are a design decision. Where a rule here overlaps a coding-standards rule, this skill takes precedence for array and DataFrame code.

Categories

Vectorization [CRITICAL]

Keep computation in compiled NumPy/pandas code instead of the Python interpreter.

RuleDescription
vec-no-python-loopsVectorize instead of Python loops, iterrows, and row-wise apply (10-1000x faster)
vec-no-incremental-growthBuild arrays and DataFrames once, not incrementally (O(n) vs O(n²))
Indexing & Mutation [CRITICAL]

Write to DataFrames in ways that are correct under Copy-on-Write and visible in the data flow.

RuleDescription
mut-loc-not-chainedAssign with .loc, never with chained indexing
mut-no-inplaceAvoid inplace=True
Data Types [HIGH]

Make dtypes an explicit decision rather than an inference result.

RuleDescription
dtype-explicit-ioSpecify dtypes when loading data
dtype-categoricalUse category dtype for low-cardinality strings
dtype-numpy-explicitChoose NumPy dtypes explicitly
Schema Validation [HIGH]

Validate tabular data where it enters the system.

RuleDescription
schema-panderaValidate DataFrames at boundaries with pandera
Reproducibility [HIGH]

Make experiments repeatable and free of hidden global state.

RuleDescription
repro-default-rngUse an explicit Generator for randomness
Transformation Style [MEDIUM]

Write DataFrame transformations that read top-to-bottom as a single pipeline.

RuleDescription
style-method-chainingExpress transformations as method chains
style-named-aggregationUse named aggregation in groupby
Typing [MEDIUM]

Type hints that carry dtype and column information.

RuleDescription
type-array-annotationsAnnotate arrays and frames with precise types
Testing [MEDIUM]

Assertions that fit floating-point arrays and DataFrames.

RuleDescription
test-numeric-assertionsCompare numeric results with tolerance-aware assertions

Quick Reference

Vectorization
python
# Whole-array operations, not loops / iterrows / apply(axis=1)
df["total"] = df["price"] * df["qty"]
rate = np.select([df["qty"] >= 100, df["qty"] >= 10], [0.2, 0.1], default=0.0)
# Collect, then build once
records = [{"id": item.id, "score": score(item)} for item in items]
results = pd.DataFrame.from_records(records)
combined = pd.concat(frames, ignore_index=True)
Indexing & Mutation
python
# .loc in one step; chained assignment never reaches df under Copy-on-Write
df.loc[df["status"] == "pending", "priority"] = "high"
# Returning form, not inplace=True
df = df.dropna(subset=["email"]).sort_values("created_at")
Data Types
python
df = pd.read_csv(
path,
dtype={"customer_id": "Int64", "zip_code": "string", "region": "category"},
parse_dates=["created_at"],
)
SEVERITY = pd.CategoricalDtype(["low", "medium", "high"], ordered=True)
embeddings = np.zeros((n, 768), dtype=np.float32)
Schema Validation
python
import pandera.pandas as pa
from pandera.typing import DataFrame, Series
class OrderSchema(pa.DataFrameModel):
order_id: Series[int] = pa.Field(unique=True)
price: Series[float] = pa.Field(ge=0)
class Config:
strict = True
def load_orders(path: str) -> DataFrame[OrderSchema]:
return OrderSchema.validate(pd.read_csv(path))
Reproducibility
python
def run_experiment(seed: int) -> Result:
rng = np.random.default_rng(seed)
split_rng, noise_rng = rng.spawn(2)
...
def add_noise(x: np.ndarray, rng: np.random.Generator) -> np.ndarray:
return x + rng.normal(scale=0.1, size=x.shape)
Transformation Style
python
monthly = (
pd.read_csv("sales.csv", parse_dates=["date"])
.assign(
revenue=lambda d: d["price"] * d["qty"],
month=lambda d: d["date"].dt.to_period("M"),
)
.loc[lambda d: d["revenue"] > 0]
.groupby("month", as_index=False)
.agg(total_revenue=("revenue", "sum"), orders=("order_id", "count"))
)
Typing
python
import numpy.typing as npt
def to_float32(values: npt.ArrayLike) -> npt.NDArray[np.float32]:
return np.asarray(values, dtype=np.float32)
Testing
python
np.testing.assert_allclose(result, expected, rtol=1e-6, atol=1e-12)
pd.testing.assert_frame_equal(result_df, expected_df, check_like=True)

See Also

  • coding-standards - General Python rules; validation-pydantic, design-no-global-singleton, and doc-type-hints have direct counterparts here
  • testing - pytest structure, fixtures, and mocking that numeric tests still follow

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
24
Repository forks
5
7-day trend score
16

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/ludo-technologies/python-best-practices/data-science/badge)](https://verified-skill.com/skills/ludo-technologies/python-best-practices/data-science)

Something wrong with this skill or its page? Tell us.