---
name: "pandas-memory-downcasting-dtypes"
description: "Shrink Pandas DataFrame memory consumption by up to 80% using optimal dtypes."
metadata:
  author: "Pandas"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "reduce pandas memory usage"
  - "downcast pandas dtypes"
  - "use categorical dtype pandas"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Pandas Memory Downcasting & Categorical Dtypes

Optimizes memory usage in Pandas: downcasting int64/float64 to int16/float32 using pd.to_numeric(downcast=...), converting low-cardinality string columns to category dtypes, and Arrow backends.

## When to Invoke
Invoke this skill whenever you need to:
- reduce pandas memory usage
- downcast pandas dtypes
- use categorical dtype pandas

## Execution SOP & Rules
1. Inspect memory footprint with df.info(memory_usage='deep').
2. Convert repeated string columns to categorical: df['status'] = df['status'].astype('category').
3. Downcast numeric types using pd.to_numeric(df[col], downcast='integer').
4. Specify engine='pyarrow' or dtype_backend='pyarrow' when reading Parquet or CSV files.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
