python-pandas
Standardizes Pandas code by favoring vectorization over loops and enforcing project-wide naming and typing conventions.
Install
mkdir -p .claude/skills/python-pandas && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16970" && unzip -o skill.zip -d .claude/skills/python-pandas && rm skill.zipInstalls to .claude/skills/python-pandas
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Write Pandas code to this project's standards — vectorised operations, Pandas-native types, and Pandera schemas. Use when importing or using pandas — transforming DataFrames or Series, handling missing values, or type-hinting tabular data.Key capabilities
- →Operate on entire Series and DataFrames using vectorized methods
- →Use `pd.NA`/`pd.NaT` for missing values instead of `np.nan`
- →Prefer nullable extension dtypes like `Int64`, `boolean`, `string`
- →Type-hint DataFrame parameters and returns with `DataFrame[Model]` using Pandera
- →Suffix DataFrame variables with `_df` for type visibility
- →Name Series variables for their contents
How it works
This skill enforces a set of coding standards for Pandas, promoting vectorized operations, Pandas-native types for missing values, and Pandera schemas for type-hinting. It guides the use of Series methods over NumPy functions and specific naming conventions.
Inputs & outputs
When to use python-pandas
- →Transforming DataFrames
- →Handling missing data values
- →Type-hinting tabular data
- →Optimizing data pipelines
About this skill
Python Pandas
Standards for working with Pandas DataFrames and Series. Extends the "prefer library
idioms" rule in python-code-style with Pandas specifics.
Vectorise
- Operate on whole Series and DataFrames; don't loop with
.apply,.iterrows, or a Pythonforover rows. Reach for Series methods —.where/.mask/.map/.clip/.str.*,.between,.isin— anddf.eval/df.queryfor arithmetic and filtering. - Prefer
Series.map(mapping)to.apply(lambda x: mapping[x]), and use&/|only for row-wise boolean masks — keepand/orfor scalar conditionals. - When you genuinely must iterate, use
.itertuples()(named, typed, fast), never.iterrows(). - Stay in Pandas types all the way to the function boundary — don't drop to Python lists
or NumPy arrays mid-pipeline and convert back, and don't convert at a call site to
satisfy an over-concrete parameter type (pass
df.columns, notdf.columns.tolist();python-code-stylehas the general rule). The reason is usually performance: a Python container forces per-element work where a Pandas operation stays vectorised. - Compute group statistics with a Pandas-native transform, not a dict round-trip:
images.groupby("source_dir")["source_dir"].transform("size")filters on group size without leaving Pandas, wherevalue_counts().to_dict()plus a row-wise.mapallocates a Python dict per call. - Name a DataFrame for what it holds (
images,upscaled_images), neverdf,dataortmp. Add adf_/_dfaffix only where the type isn't obvious — most often when a DataFrame and a Series of the same concept sit side by side — and follow whichever affix the surrounding code already uses. Name Series for their contents too (file_size_bytes, nots). - Time a performance claim on representative data before acting on it. Idiomatic Pandas
usually wins, but both the size of the win and where it comes from move with the data:
transform("size")beatvalue_counts().to_dict()plus a row-wise.mapby 3.7–10× across group counts from 100 to 10k, while dropping the.to_dict()alone recovered anywhere from most of that to under a tenth — the cost is the per-element lookup rather than building the dict, so replace the lookup, not just the conversion.groupby(...).filter(...)was no faster than what it replaced.
Don't mix NumPy into Pandas
- Use
pd.NA/pd.NaTfor missing values, notnp.nan, and prefer the nullable extension dtypes (Int64,boolean,string) so missingness is first-class — NumPy float columns silently coercepd.NAtoNaN. - Prefer Series methods over
np.*functions on a Series (including via.apply), and never use.values(thePD011lint flags it) — reach for.to_numpy()only at a boundary needing a raw array. - Don't store NaN as a sentinel; model "missing" explicitly with a nullable dtype.
- Keeping everything Pandas-native also keeps a future move to Polars tractable.
Pandera schemas
- Lean on Pandera: type-hint every DataFrame parameter and return with
DataFrame[Model]. The payoff is readability — the schema becomes explicit at every reference — so use it ubiquitously, not sparingly. - A genuinely schema-polymorphic helper — one that works on whatever columns it is handed
— takes a bare
pd.DataFrameinstead, and documents in its docstring the contract it does rely on (index levels, ordering, any required column). Don't invent a union model to forceDataFrame[Model]onto it, and don't leave the contract implicit. - Give each schema model its own module, and keep the raw (as-ingested) schema in a separate module from the processed (validated or derived) one.
- Back categorical columns with a
Categorydtype built from anEnum's values (iterate the Enum to build the categories), and annotate timestamp columns aspd.Timestamp.
When not to use it
- →When the task requires iterating over rows with `.iterrows()`
- →When the task involves mixing NumPy arrays mid-pipeline
- →When the task does not involve Pandas DataFrames or Series
Limitations
- →Does not support using `.iterrows()` for iteration
- →Does not support mixing NumPy arrays with Pandas types mid-pipeline
- →Does not support using `np.nan` for missing values
How it compares
This skill provides explicit guidelines for writing idiomatic and efficient Pandas code, contrasting with a generic approach that might use inefficient loops or non-native types.
Compared to similar skills
python-pandas side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| python-pandas (this skill) | 0 | 1mo | No flags | Intermediate |
| jupyter-notebook | 30 | 6mo | Review | Intermediate |
| sexp | 3 | 6mo | No flags | Advanced |
| r-code | 0 | 4mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
jupyter-notebook
davila7
Use when the user asks to create, scaffold, or edit Jupyter notebooks (`.ipynb`) for experiments, explorations, or tutorials; prefer the bundled templates and run the helper script `new_notebook.py` to generate a clean starting notebook.
sexp
atopile
How the Zig S-expression engine and typed KiCad models work, how they are exposed to Python (pyzig_sexp), and the invariants around parsing, formatting, and freeing.
r-code
dslc-io
Guide for writing R code. Use when writing new functions, designing APIs, or reviewing/modifying existing R code.
root-finding
parcadei
Problem-solving strategies for root finding in numerical methods
streamlit
sverzijl
When working with Streamlit web apps, data dashboards, ML/AI app UIs, interactive Python visualizations, or building data science applications with Python
backtesting-frameworks
wshobson
Build robust backtesting systems for trading strategies with proper handling of look-ahead bias, survivorship bias, and transaction costs. Use when developing trading algorithms, validating strategies, or building backtesting infrastructure.