mcpField
D
data-python

data-python

github.com/alexanderstephenthompsonData & databases48 installs
Repository

About data-python

data-python is a skill for Python data-processing code using pandas, polars, and pyspark. It focuses on scalable DataFrame practices, from vectorization and schema validation to memory-aware types.

Key features

  1. 01Vectorized DataFrame operations
  2. 02Schema validation
  3. 03Explicit dtype handling
  4. 04Memory-efficient processing
  5. 05Method chaining
  6. 06Data pipeline error handling

Use cases

  1. 01Replace row loops with DataFrame operations
  2. 02Validate incoming data schemas
  3. 03Reduce memory use on large datasets
  4. 04Build readable transformation pipelines

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/alexanderstephenthompson/claude-hub --skill data-python

After installing, type/data-pythonin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

assets/
pandas-cheatsheet.md
references/
memory-optimization.md
vectorization.md

Details

From the project README

Data Python Skill

Version: 1.0 Stack: Python (pandas, polars, pyspark)

Python makes it easy to write data processing code that works on sample data and fails on real data. iterrows() takes 30 seconds on 10K rows and 30 minutes on 10M. A DataFrame without explicit dtypes uses 8x the memory it needs. Chained indexing creates silent copies that lose your changes. These aren't edge cases — they're the default behavior of pandas when you write it like regular Python.

Vectorized operations, explicit schemas, and proper dtypes mean your code scales from prototype to production without rewriting.


Scope and Boundaries

This skill covers:

  • DataFrame patterns (pandas, polars, pyspark)
  • Data type handling and validation
  • Memory-efficient processing
  • Vectorized operations over loops
  • Method chaining patterns
  • Error handling for data pipelines

Defers to other skills:

  • code-quality: General code structure, testing, naming
  • data-sql: Query patterns when using SQL interfaces
  • data-pipelines: Orchestration and ETL architecture

Use this skill when: Writing Python code that processes data.


Core Principles

  1. Vectorize, Don't Loop — Use DataFrame operations, not row iteration.
  2. Fail Fast on Bad Data — Validate early, reject invalid data at boundaries.
  3. Memory Awareness — Know your data size, use appropriate dtypes.
  4. Immutable Transforms — Chain operations, don't mutate in place.
  5. Explicit Schemas — Define expected columns and types upfront.

Patterns

Method Chaining
# Good - readable pipeline
result = (
    df
    .query("status == 'active'")
    .assign(total=lambda x: x["quantity"] * x["price"])
    .groupby("category")
    .agg({"total": "sum"})
    .sort_values("total", ascending=False)
)

# Bad - intermediate variables obscure flow
filtered = df[df["status"] == "active"]
filtered["total"] = filtered["quantity"] * filtered["price"]
grouped = filtered.groupby("category")
result = grouped.agg({"total": "sum"})
result = result.sort_values("total", ascending=False)
Schema Validation
EXPECTED_COLUMNS = {"id", "name", "value", "timestamp"}
REQUIRED_COLUMNS = {"id", "value"}

def validate_schema(df: pd.DataFrame) -> pd.DataFrame:
    missing = REQUIRED_COLUMNS - set(df.columns)
    if missing:
        raise ValueError(f"Missing required columns: {missing}")
    return df[list(EXPECTED_COLUMNS & set(df.columns))]
Type Optimization
def optimize_dtypes(df: pd.DataFrame) -> pd.DataFrame:
    """Downcast numeric types to reduce memory."""
    for col in df.select_dtypes(include=["int"]).columns:
        df[col] = pd.to_numeric(df[col], downcast="integer")
    for col in df.select_dtypes(include=["float"]).columns:
        df[col] = pd.to_numeric(df[col], downcast="float")
    return df

Anti-Patterns

Anti-PatternProblemFix
for row in df.iterrows()Slow, defeats vectorizationUse vectorized operations
df["col"] = df.apply(...)Usually slower than vectorizedUse np.where or df.assign
Chained indexing df["a"]["b"]SettingWithCopyWarningUse df.loc[:, "a"]
Loading entire file to check schemaWastes memoryUse nrows=100 or chunking
Ignoring dtypes on readMemory bloatSpecify dtype= parameter

Checklist

  • No iterrows() or itertuples() for computation
  • Explicit dtypes on file reads
  • Schema validation at boundaries
  • Method chaining for transforms
  • Memory profiled for large datasets

References

  • references/vectorization.md — Vectorized operations and performance
  • references/memory-optimization.md — Memory optimization techniques

Assets

  • assets/pandas-cheatsheet.md — Quick reference for pandas operations

Comments

Markdown supported