python-data-wrangling
Skill2 starsChanged 10 months agoMITView on GitHub
Modern data wrangling with pandas and polars. Use this skill when working with tabular data, need to choose between pandas/polars, or want to write idiomatic data manipulation code. Covers method chaining, idiomatic operations, performance considerations, and migration between libraries.
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 109
When lazy helps vs hurts
- Distinctive: line 130
when().then().otherwise() patterns
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Python Data Wrangling
Modern patterns for pandas and polars data manipulation.
Decision Matrix: Pandas vs Polars
| Factor | Pandas | Polars | Winner |
| Data size | <1GB | >1GB, especially >10GB | Polars for large data |
| Query optimization | No | Yes (lazy evaluation) | Polars |
| Ecosystem integration | Vast (sklearn, viz) | Growing | Pandas for ML/viz |
| API familiarity | DataFrame standard | Rust-inspired | Pandas for teams |
| Performance | Good | Excellent (2-10x) | Polars |
| Memory usage | Higher | Lower | Polars |
General guidance:
- Use pandas when: <1GB data, heavy ML/viz integration, team familiarity critical
- Use polars when: >1GB data, performance critical, greenfield projects
Modern Pandas Patterns
Method Chaining
Chain operations for readability
result = (
df
.assign(
total=lambda x: x["price"] * x["quantity"],
date=lambda x: pd.to_datetime(x["date"])
)
.query("total > 100")
.sort_values("total", ascending=False)
.groupby("category")
.agg({"total": ["sum", "mean"]})
.reset_index()
)See pandas-method-chaining.md for:
- Lambda vs direct assignment
- Pipe with custom functions
- Handling complex transformations
Idiomatic Operations
# Use .loc for explicit indexing
df.loc[df["score"] > 80, "grade"] = "A"
# Use .pipe() for custom transformations
result = df.pipe(normalize_columns).pipe(remove_duplicates)
# Use .assign() for new columns
df = df.assign(
log_value=lambda x: np.log(x["value"]),
is_high=lambda x: x["value"] > x["value"].median()
)GroupBy Patterns
# Named aggregations (pandas 0.25+)
summary = df.groupby("category").agg(
total_sales=("sales", "sum"),
avg_sales=("sales", "mean"),
num_transactions=("sales", "count")
)See pandas-groupby-patterns.md for:
- Window functions
- Multiple grouping levels
- Custom aggregations
Polars Patterns
Lazy Evaluation
Use lazy API for query optimization
import polars as pl
result = (
pl.scan_csv("data.csv") # Lazy
.filter(pl.col("value") > 100)
.group_by("category")
.agg([
pl.col("sales").sum().alias("total_sales"),
pl.col("sales").mean().alias("avg_sales")
])
.collect() # Execute
)See polars-lazy-evaluation.md for:
- When lazy helps vs hurts
- Streaming for huge data
- Query plan inspection
Polars Expressions
Use expressions for vectorized operations
result = df.select([
pl.col("name"),
(pl.col("salary") * 1.1).alias("new_salary"),
pl.when(pl.col("age") > 30)
.then(pl.lit("senior"))
.otherwise(pl.lit("junior"))
.alias("level")
])See polars-expressions.md for:
- Expression composition
- when().then().otherwise() patterns
- List and struct operations
Migration Guide
Pandas → Polars
| Pandas | Polars | Notes |
df["col"] | df["col"] or pl.col("col") | Expressions preferred |
df[df["x"] > 5] | df.filter(pl.col("x") > 5) | Method-based |
df.groupby("x").agg({"y": "sum"}) | df.group_by("x").agg(pl.col("y").sum()) | Expression-based |
See migration-pandas-polars.md for complete patterns.
Performance Tips
Pandas Performance
# Use vectorized operations
df["result"] = df["a"] + df["b"] # Good
# Use categorical for low-cardinality columns
df["category"] = df["category"].astype("category")
# Use eval for complex expressions
df.eval("total = price * quantity", inplace=True)Polars Performance
# Use scan instead of read for lazy
df = pl.scan_csv("data.csv")
# Use streaming for data larger than memory
result = df.collect(streaming=True)Anti-Patterns to Avoid
| Avoid | Use Instead |
df.iterrows() | Vectorized operations |
Chained indexing df["a"]["b"] = x | .loc |
| Growing DataFrames in loops | pd.concat() outside loop |
| Mixed types in columns | Consistent types |
source: pandas user guide, polars documentation
In this repository38 other files it gives its agents.
- Data Engineering Cloud InfrastructureSkill
- data-eng-data-qualitySkill
- data-eng-streaming-patternsSkill
- data-eng-testing-patternsSkill
- data-eng-warehouse-patternsSkill
- DevOps CI/CD PatternsSkill
- devops-docker-patternsSkill
- devops-monitoring-observabilitySkill
- devops-terraform-patternsSkill
- git-advanced-operationsSkill
- git-workflow-patternsSkill
- modern-python-patternsSkill
- python-api-developmentSkill
- python-async-patternsSkill
- python-data-pipelinesSkill
- python-devops-automationSkill
- python-error-handlingSkill
- python-package-developmentSkill
- python-performanceSkill
- python-testingSkill
- customizing-vectors-rSkill
- designing-oop-rSkill
- developing-packages-rSkill
- metaprogramming-rlangSkill
- optimizing-rSkill
- writing-tidyverse-rSkill
- sql-advanced-featuresSkill
- sql-analytics-patternsSkill
- sql-data-modelingSkill
- SQL Integration PatternsSkill
- sql-query-fundamentalsSkill
- sql-query-optimizationSkill
- sql-transformationsSkill
- API DesignSkill
- webdev-html-css-patternsSkill
- webdev-javascript-fundamentalsSkill
- webdev-react-patternsSkill
- webdev-typescript-patternsSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

