Skip to content
Back to skills

Pandas Performance

ASecurity

Speeds up slow pandas code by measuring first, then vectorizing, shrinking dtypes and chunking reads. Use it when a script is slow or runs out of memory.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 15, 2026
ai-agentspythongotestingperformance

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill pandas-performance --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pandas Performance?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pandas Performance
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-pandas-performance/badge)](https://www.skillsdirectory.com/skills/workspace-templates-pandas-performance)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: pandas-performance
description: Speeds up slow pandas code by measuring first, then vectorizing, shrinking dtypes and chunking reads. Use it when a script is slow or runs out of memory.
---

# Pandas performance

Measure, change one thing, measure again, and prove the output did not change.

## Steps

1. Build a representative sample and keep the current output as the reference. Time the slow path with `time.perf_counter()` or `%timeit`, and record memory with `df.memory_usage(deep=True).sum()`.
2. Profile to find the hot line (`python -m cProfile -s cumtime script.py`). Do not optimize lines that are not hot.
3. Replace row loops. `iterrows`, `itertuples` and `apply(axis=1)` become column arithmetic, `np.where`, `np.select`, `.map` with a dict, or `merge` for lookups.
4. Shrink dtypes: `category` for low-cardinality strings, `int32` or `float32` where range allows (check with `pd.to_numeric(downcast=...)`), nullable ints only when nulls exist, and `datetime64` instead of strings.
5. Read less: pass `usecols=`, set `dtype=` at load, and read big files with `chunksize=` or switch to Parquet. Aggregate per chunk, then combine.
6. Avoid repeated `concat` in a loop; collect pieces in a list and concat once. Filter before merging, not after.
7. Compare the new result with the reference using `pd.testing.assert_frame_equal`.

## Rules

- No optimization without a measurement showing it helps.
- If the data is beyond one machine, say so and name polars or DuckDB rather than forcing pandas.

## Report

A table of step, time and memory before and after, the one change that mattered most, and the equality check result.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.