Skip to content
Back to skills

Write Dataframe Transformation

ASecurity

Writes pandas or polars code for a described transformation with built-in checks on row counts, nulls, key uniqueness and join cardinality. Use when reshaping, joining or aggregating data.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 26, 2026
ai-agentspythongoexpressapi

Works with

  • api

Security analysis

A100/100

Scanned November 26, 2026

npx -y skills add hermes-hq/hodios-dist --skill write-dataframe-transformation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Write Dataframe Transformation?

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

Security grade badge for Write Dataframe Transformation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hermes-hq-write-dataframe-transformation/badge)](https://www.skillsdirectory.com/skills/hermes-hq-write-dataframe-transformation)

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: write-dataframe-transformation
description: Writes pandas or polars code for a described transformation with built-in checks on row counts, nulls, key uniqueness and join cardinality. Use when reshaping, joining or aggregating data.
license: CC0-1.0
arguments:
  - input_description
  - desired_output
  - library
argument-hint: <input_description> <desired_output> [library]
disable-model-invocation: true
metadata:
  version: 1.1.0
  kind: prompt
  category: data-exploration
  source: https://hermes-ide.com/prompts/write-dataframe-transformation
  catalog: 2026.1014.1
---

# Write a dataframe transformation

## Inputs

- `input_description` (required): The input tables, with column names, types, keys and a few sample rows if you can share them.
- `desired_output` (required): What the result should look like (grain, columns, filters, aggregations), ideally with an example row.
- `library` (optional; one of: pandas, polars; default: pandas): The dataframe library to use.

Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.

<context>
Dataframe code usually fails silently, not loudly: a join on a key that is not unique multiplies rows, a left join leaves nulls that later vanish in an aggregation, a string key with trailing spaces matches nothing, and dates parsed in the wrong format shift by months. The output looks plausible and is wrong. Defensive transformations state the grain of every table, check keys before joining, assert row counts and nulls at each step, and fail with a clear message instead of producing a wrong table.
</context>

<task>
Write $library code that turns this input:
<input>
$input_description
</input>
into this output:
<output>
$desired_output
</output>

1. State the grain (what one row represents) and the key of each input and of the output.
2. Plan the steps in order: load or receive, clean types and keys, filter, join, reshape, aggregate, final selection and ordering.
3. Write the code as a function that takes the input dataframes and returns the output, with a short comment on each step.
4. After each step that can change row counts or introduce nulls, add a check:
   - keys: uniqueness on the side that should be unique, before every join;
   - joins: the expected cardinality (pandas `merge(..., validate="many_to_one")`, polars `join(..., validate="m:1")`) and a count of unmatched keys;
   - row counts: expected equal, smaller or larger than before, and by how much;
   - nulls: in key columns and in columns the output requires;
   - aggregates: totals that should be preserved (for example the sum of amounts before and after reshaping).
5. Make checks raise an error with a message that names the step and the offending values; do not use bare `assert`, which `python -O` removes.
6. Add a tiny test: a few hand-made input rows, including one edge case (duplicate key, missing value or unmatched join), and the exact expected output.
</task>

<constraints>
- Use idiomatic, vectorised $library: for pandas, method chaining where it stays readable, `.loc` for assignment, no chained assignment and no row-wise `apply` when a vectorised form exists; for polars, expressions with `pl.col`, and the lazy API for large data.
- Write code compatible with current stable releases, and name any feature that needs a recent version.
- Do not guess column names, types or business rules. If the description does not give the columns and keys of each input, or the grain of the output, stop and ask for exactly those, with a one-line example of the detail you need; do not write code against invented columns.
- For smaller gaps (for example which duplicate to keep, or how to treat unmatched rows), choose the safest behaviour, list it under Assumptions, and make it easy to change.
- Keep it self-contained: imports at the top, no reading from paths you invented; take dataframes as parameters.
</constraints>

<output_format>
## Assumptions
Bullets: grains, keys and every assumption made.
## Code
One fenced Python block with the function and its checks.
## What the checks catch
A table: check | step | the failure it prevents.
## Test
A fenced Python block with the small test and its expected output.
</output_format>

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.