pandas-patterns
Skill11 starsChanged 6 months agoMITView on GitHub
Use when writing or reviewing pandas code. Covers idiomatic, vectorized, memory-efficient patterns; avoiding SettingWithCopyWarning, chained indexing, and slow apply loops.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- langchain-ai/docstheir own version, first seen Sep 15, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- langchain-ai/docs★ 424same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- data-cleaningSkill
- experiment-trackingSkill
- exploratory-data-analysisSkill
- feature-engineeringSkill
- hyperparameter-tuningSkill
- imbalanced-dataSkill
- llm-finetuningSkill
- ml-debuggingSkill
- model-evaluationSkill
- model-servingSkill
- pytorch-training-loopSkill
- rag-pipelineSkill
- reproducible-mlSkill
- sklearn-pipelinesSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 52
Read big files in chunks (chunksize=) or switch to Polars/DuckDB when pandas is the bottleneck.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Pandas Patterns
Overview
Most pandas pain comes from three things: chained indexing, row-wise apply, and ignoring dtypes/memory. This skill encodes the idioms that keep pandas correct and fast.
When to use
- Writing data-wrangling code.
- Code is slow, leaks memory, or throws
SettingWithCopyWarning. - Reviewing someone's pandas for correctness.
Core rules
- Assign with
.loc, never chained.df.loc[df["age"] > 30, "segment"] = "senior" # correct # df[df["age"] > 30]["segment"] = "senior" # WRONG: SettingWithCopyWarning, no-op risk - Vectorize instead of
apply(axis=1). Row-wise apply is a Python loop.df["bmi"] = df["weight"] / df["height"] ** 2 # fast # df.apply(lambda r: r.weight / r.height**2, axis=1) # 100x slower - Use
np.select/np.wherefor conditional columns.import numpy as np df["tier"] = np.select( [df.spend > 1000, df.spend > 100], ["gold", "silver"], default="bronze", ) - Downcast dtypes to cut memory:
categoryfor low-cardinality strings,int32/float32where safe.df["country"] = df["country"].astype("category") - Prefer
mergeover loops for joins, and validate join cardinality:df = orders.merge(users, on="user_id", how="left", validate="m:1")
Performance toolkit
df.groupby(..., observed=True).agg(...)—observed=Trueavoids exploding categorical combinations.pd.eval/df.query()for large boolean filters.- Read big files in chunks (
chunksize=) or switch to Polars/DuckDB when pandas is the bottleneck. df.pipe(fn)to compose transformations without intermediate variables.
Method chaining (readable + copy-safe)
result = (
df
.query("status == 'active'")
.assign(revenue=lambda d: d.qty * d.price)
.groupby("region", observed=True)
.agg(total=("revenue", "sum"))
.reset_index()
)Pitfalls
inplace=Truerarely saves memory and breaks chaining — avoid it.- Iterating with
iterrows— almost always replaceable with vectorization oritertuples. - Floating-point group keys — round or use integer/category keys.
- Silent dtype upcasts (int → float when NaN appears) — use nullable
Int64if you must keep integers.
Hand-off
Clean, vectorized transformations that downstream skills (feature-engineering, model-evaluation) can run quickly on full datasets.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

