agentleFS
MindrallyMindrally/skills/pandas-best-practices/SKILL.md

pandas-best-practices

Skill266 starsChanged 10 months agoApache-2.0View on GitHub

Best practices for Pandas data manipulation, analysis, and DataFrame operations in Python

The file

Show its rules and text

We split this skill into the rules it gives an agent

48 rules. About 0 are common, 15 are distinctive, and 33 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈15

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 33

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write concise, technical responses with accurate Python examples

    line 12
  2. Distinctive:

    Use functional programming.

    line 14
  3. Distinctive:

    Prefer vectorized operations over explicit loops

    line 15
  4. Distinctive:

    Use descriptive variable names reflecting data content

    line 16
  5. Distinctive:

    Follow PEP 8 style guidelines

    line 17
  6. Very specific:

    Use pd.read_csv(), pd.read_excel(), pd.read_json() with appropriate parameters

    line 21
  7. Very specific:

    Use parse_dates for automatic datetime parsing

    line 23
  8. Very specific:

    Use chunksize for reading large files incrementally

    line 25
  9. Very specific:

    Use .loc[] for label-based indexing

    line 29
  10. Very specific:

    Use .iloc[] for integer position-based indexing

    line 30
  11. Very specific:

    Avoid chained indexing (e.g., df['col'][0]) - use .loc or .iloc instead

    line 31
  12. Very specific:

    Use boolean indexing for conditional selection: df[df['col'] > value]

    line 32
  13. Very specific:

    Use .query() method for complex filtering conditions

    line 33
  14. Distinctive:

    Prefer method chaining for data transformations when possible

    line 37
  15. Very specific:

    Use .pipe() for applying custom functions in a chain

    line 38
  16. Distinctive:

    Keep chains readable by breaking across multiple lines

    line 40
  17. Very specific:

    Check for missing data with .isna() and .info()

    line 46
  18. Very specific:

    Use pd.NA for nullable integer and boolean types

    line 48
  19. Distinctive:

    Document decisions about missing data handling

    line 49
  20. Very specific:

    Check for duplicates with .duplicated() and handle appropriately

    line 55
  21. Very specific:

    Use .describe() for quick statistical overview

    line 56
  22. Very specific:

    Use .astype() for explicit type conversion

    line 60
  23. Very specific:

    Use pd.to_datetime() for date parsing

    line 61
  24. Very specific:

    Use pd.to_numeric() with errors='coerce' for safe numeric conversion

    line 62
  25. Very specific:

    Use .groupby() for efficient aggregation operations

    line 69
  26. Distinctive:

    Use named aggregation for clearer output column names

    line 71
  27. Very specific:

    Consider .transform() for broadcasting results back to original shape

    line 72
  28. Very specific:

    Use .pivot_table() for multi-dimensional aggregation

    line 76
  29. Very specific:

    Use .melt() to convert wide to long format

    line 77
  30. Very specific:

    Use .pivot() to convert long to wide format

    line 78
  31. Very specific:

    Use .stack() and .unstack() for hierarchical index manipulation

    line 79
  32. Distinctive:

    Use categorical data types for low-cardinality strings

    line 85
  33. Very specific:

    Use pd.eval() and .eval() for large expression evaluation

    line 87
  34. Very specific:

    Use vectorized operations instead of .apply() with row-wise functions

    line 91
  35. Distinctive:

    Prefer built-in aggregation functions over custom ones

    line 92
  36. Very specific:

    Use .values or .to_numpy() for NumPy operations when faster

    line 93
  37. Very specific:

    Avoid iterating with .iterrows() - use vectorized operations

    line 97
  38. Distinctive:

    Don't modify DataFrames while iterating

    line 98
  39. Distinctive:

    Avoid growing DataFrames row by row - collect in list and create once

    line 100
  40. Very specific:

    Use DatetimeIndex for time series data

    line 104
  41. Very specific:

    Use .shift() and .diff() for lag operations

    line 106
  42. Very specific:

    Use .rolling() and .expanding() for window calculations

    line 107
  43. Very specific:

    Use .merge() for SQL-style joins

    line 111
  44. Very specific:

    Use validate parameter to check join cardinality

    line 113
  45. Very specific:

    Use .concat() for stacking DataFrames

    line 114
  46. Very specific:

    Use snake_case for column names when possible

    line 119
  47. Distinctive:

    Document data sources and transformations

    line 120
  48. Distinctive:

    Keep notebooks reproducible with clear cell execution order

    line 121

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

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.