Skip to main content
skill CX Codex

pandas-best-practices — Claude Code skill: setup and guide

Guides the AI assistant to write idiomatic Pandas code using vectorization, method chaining, and proper data types. Useful for data analysis and refactoring slow DataFrame transformations.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Mindrally/skills --skill pandas-best-practices -a claude-code
Open on GitHub

What pandas-best-practices does

This skill instructs the agent to write performant Python code for Pandas pipelines. It directs the model to replace Python loops with vectorized routines and functional patterns. During ingestion with pd.read_csv() or pd.read_json(), the agent declares column types with dtype and parses timestamps upfront. Categorical types are assigned to low-cardinality strings. This cuts memory usage immediately.

Data pipelines rely on method chaining. Operations use .assign() and .pipe() in readable multiline blocks. The skill prevents fragile chained indexing by enforcing .loc[] and .iloc[] for selections. Iterating over rows with .iterrows() degrades execution speed on large datasets, so the guidelines push calculations into native Pandas or NumPy routines. Slices require explicit .copy() calls to prevent SettingWithCopyWarning errors.

For table joins, the assistant uses .merge() while validating relationship cardinality with the validate argument. Time series workflows rely on DatetimeIndex and rolling window aggregations. The agent avoids row-by-row DataFrame construction, collecting raw records in lists first. Notebooks stay clean and reproducible.

What it helps with

  • Replace slow row iteration with vectorized operations
  • Eliminate SettingWithCopyWarning errors during DataFrame slicing
  • Reduce memory consumption by converting string columns to categories
  • Validate join cardinality automatically using the validate parameter in .merge()

Example prompts for the agent

  • Optimize loading transactions.csv by configuring explicit dtypes and date parsing
  • Refactor this DataFrame pipeline to use method chaining instead of .iterrows()
  • Join users.csv and orders.csv using .merge() with one-to-many validation

How to install pandas-best-practices

1Skills CLI (Vercel)

npx skills add Mindrally/skills --skill pandas-best-practices -a claude-code

2Manually: put the files in place

~/.claude/skills/pandas-best-practices/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/pandas-best-practices/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about pandas-best-practices

How do I install pandas-best-practices in Claude Code?

Run npx skills add Mindrally/skills --skill pandas-best-practices -a claude-code. The skill file will be stored at ~/.claude/skills/pandas-best-practices/SKILL.md.

What does pandas-best-practices do?

It instructs the AI assistant to write idiomatic, vectorized Pandas code without classes or row-wise loops. The rules prevent chained indexing issues and enforce method chaining.

How does this skill optimize DataFrame memory usage?

The instructions require explicit dtype declarations on data load, numeric type downcasting, and converting low-cardinality strings to categorical types.

Source text

SKILL.md · Apache-2.0
---
name: pandas-best-practices
description: Best practices for Pandas data manipulation, analysis, and DataFrame operations in Python
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# Pandas Best Practices

Expert guidelines for Pandas development, focusing on data manipulation, analysis, and efficient DataFrame operations.

## Code Style and Structure

- Write concise, technical responses with accurate Python examples
- Prioritize reproducibility in data analysis workflows
- Use functional programming; avoid unnecessary classes
- Prefer vectorized operations over explicit loops
- Use descriptive variable names reflecting data content
- Follow PEP 8 style guidelines

## DataFrame Creation and I/O

- Use `pd.read_csv()`, `pd.read_excel()`, `pd.read_json()` with appropriate parameters
- Specify `dtype` parameter to ensure correct data types on load
- Use `parse_dates` for automatic datetime parsing
- Set `index_col` when the data has a natural index column
- Use `chunksize` for reading large files incrementally

## Data Selection

- Use `.loc[]` for label-based indexing
- Use `.iloc[]` for integer position-based indexing
- Avoid chained indexing (e.g., `df['col'][0]`) - use `.loc` or `.iloc` instead
- Use boolean indexing for conditional selection: `df[df['col'] > value]`
- Use `.query()` method for complex filtering conditions

## Method Chaining

- Prefer method chaining for data transformations when possible
- Use `.pipe()` for applying custom functions in a chain
- Chain operations like `.assign()`, `.query()`, `.groupby()`, `.agg()`
- Keep chains readable by breaking across multiple lines

## Data Cleaning and Validation

### Missing Data

- Check for missing data with `.isna()` and `.info()`
- Handle missing data appropriately: `.fillna()`, `.dropna()`, or imputation
- Use `pd.NA` for nullable integer and boolean types
- Document decisions about missing data handling

### Data Quality Checks

- Implement data quality checks at the beginning of analysis
- Validate data types with `.dtypes` and convert as needed
- Check for duplicates with `.duplicated()` and handle appropriately
- Use `.describe()` for quick statistical overview

### Type Conversion

- Use `.astype()` for explicit type conversion
- Use `pd.to_datetime()` for date parsing
- Use `pd.to_numeric()` with `errors='coerce'` for safe numeric conversion
- Utilize categorical data types for low-cardinality string columns

## Grouping and Aggregation

### GroupBy Operations

- Use `.groupby()` for efficient aggregation operations
- Specify aggregation functions with `.agg()` for multiple operations
- Use named aggregation for clearer output column names
- Consider `.transform()` for broadcasting results back to original shape

### Pivot Tables and Reshaping

- Use `.pivot_table()` for multi-dimensional aggregation
- Use `.melt()` to convert wide to long format
- Use `.pivot()` to convert long to wide format
- Use `.stack()` and `.unstack()` for hierarchical index manipulation

## Performance Optimization

### Memory Efficiency

- Use categorical data types for low-cardinality strings
- Downcast numeric types when appropriate
- Use `pd.eval()` and `.eval()` for large expression evaluation

### Computation Speed

- Use vectorized operations instead of `.apply()` with row-wise functions
- Prefer built-in aggregation functions over custom ones
- Use `.values` or `.to_numpy()` for NumPy operations when faster

### Avoiding Common Pitfalls

- Avoid iterating with `.iterrows()` - use vectorized operations
- Don't modify DataFrames while iterating
- Be aware of SettingWithCopyWarning - use `.copy()` when needed
- Avoid growing DataFrames row by row - collect in list and create once

## Time Series Operations

- Use `DatetimeIndex` for time series data
- Leverage `.resample()` for time-based aggregation
- Use `.shift()` and `.diff()` for lag operations
- Use `.rolling()` and `.expanding()` for window calculations

## Merging and Joining

- Use `.merge()` for SQL-style joins
- Specify `how` parameter: 'inner', 'outer', 'left', 'right'
- Use `validate` parameter to check join cardinality
- Use `.concat()` for stacking DataFrames

## Key Conventions

- Import as `import pandas as pd`
- Use `snake_case` for column names when possible
- Document data sources and transformations
- Keep notebooks reproducible with clear cell execution order

© Mindrally · Apache-2.0 · Mindrally/skills

Similar skills

All skills for Data and databases →

From the same set214

unity A skill that makes your coding agent follow Unity conventions: component architecture, ScriptableObjects, object pooling and profiler work. CX Codex +1 908installs design-systems Walks your agent through design tokens, a component library and accessibility rules in one project. CX Codex +1 903installs wordpress The wordpress skill gives an agent a rulebook for WordPress and WooCommerce work in PHP. It keeps code inside WordPress standards and reminds the agent about hooks, nonces and prepared queries. CX Codex +1 894installs mongodb-development MongoDB development rules: schemas, indexes, aggregation pipelines, Mongoose and Payload CMS. Useful when the agent writes a TypeScript backend. CX Codex +1 891installs scikit-learn-best-practices A skill that hands your agent scikit-learn conventions: pipelines, cross-validation, metrics, model persistence. Useful when you write ML code in Python. CX Codex +1 888installs astro A skill that tells the agent how to build Astro sites: static generation, partial hydration, file-based routing and as little client-side JavaScript as possible. CX Codex +1 886installs beautifulsoup-parsing Teaches AI agents to parse HTML and XML with BeautifulSoup in Python. Helps write cleaner scrapers with safe data extraction and DOM navigation. CX Codex +1 877installs bash-scripting This skill gives the agent rules for writing Bash scripts: input validation, error handling, portability. Useful when the agent writes deploy, backup or cron tasks. CX Codex +1 875installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor