{"id":"pandas-pro","name":"pandas-pro","summary":"データ解析、操作、変換のためのpandasデータフレーム操作を実行します。pandasのデータフレーム、データクレンジング、集計、マージ、または時系列解析の作業に使用します。","body":"# Pandas Pro\n\nExpert pandas developer specializing in efficient data manipulation, analysis, and transformation workflows with production-grade performance patterns.\n\n## Core Workflow\n\n1. **Assess data structure** — Examine dtypes, memory usage, missing values, data quality:\n   ```python\n   print(df.dtypes)\n   print(df.memory_usage(deep=True).sum() / 1e6, \"MB\")\n   print(df.isna().sum())\n   print(df.describe(include=\"all\"))\n   ```\n2. **Design transformation** — Plan vectorized operations, avoid loops, identify indexing strategy\n3. **Implement efficiently** — Use vectorized methods, method chaining, proper indexing\n4. **Validate results** — Check dtypes, shapes, null counts, and row counts:\n   ```python\n   assert result.shape[0] == expected_rows, f\"Row count mismatch: {result.shape[0]}\"\n   assert result.isna().sum().sum() == 0, \"Unexpected nulls after transform\"\n   assert set(result.columns) == expected_cols\n   ```\n5. **Optimize** — Profile memory, apply categorical types, use chunking if needed\n\n## Reference Guide\n\nLoad detailed guidance based on context:\n\n| Topic | Reference | Load When |\n|-------|-----------|-----------|\n| DataFrame Operations | `references/dataframe-operations.md` | Indexing, selection, filtering, sorting |\n| Data Cleaning | `references/data-cleaning.md` | Missing values, duplicates, type conversion |\n| Aggregation & GroupBy | `references/aggregation-groupby.md` | GroupBy, pivot, crosstab, aggregation |\n| Merging & Joining | `references/merging-joining.md` | Merge, join, concat, combine strategies |\n| Performance Optimization | `references/performance-optimization.md` | Memory usage, vectorization, chunking |\n\n## Code Patterns\n\n### Vectorized Operations (before/after)\n\n```python\n# ❌ AVOID: row-by-row iteration\nfor i, row in df.iterrows():\n    df.at[i, 'tax'] = row['price'] * 0.2\n\n# ✅ USE: vectorized assignment\ndf['tax'] = df['price'] * 0.2\n```\n\n### Safe Subsetting with `.copy()`\n\n```python\n# ❌ AVOID: chained indexing triggers SettingWithCopyWarning\ndf['A']['B'] = 1\n\n# ✅ USE: .loc[] with explicit copy when mutating a subset\nsubset = df.loc[df['status'] == 'active', :].copy()\nsubset['score'] = subset['score'].fillna(0)\n```\n\n### GroupBy Aggregation\n\n```python\nsummary = (\n    df.groupby(['region', 'category'], observed=True)\n    .agg(\n        total_sales=('revenue', 'sum'),\n        avg_price=('price', 'mean'),\n        order_count=('order_id', 'nunique'),\n    )\n    .reset_index()\n)\n```\n\n### Merge with Validation\n\n```python\nmerged = pd.merge(\n    left_df, right_df,\n    on=['customer_id', 'date'],\n    how='left',\n    validate='m:1',          # asserts right key is unique\n    indicator=True,\n)\nunmatched = merged[merged['_merge'] != 'both']\nprint(f\"Unmatched rows: {len(unmatched)}\")\nmerged.drop(columns=['_merge'], inplace=True)\n```\n\n### Missing Value Handling\n\n```python\n# Forward-fill then interpolate numeric gaps\ndf['price'] = df['price'].ffill().interpolate(method='linear')\n\n# Fill categoricals with mode, numerics with median\nfor col in df.select_dtypes(include='object'):\n    df[col] = df[col].fillna(df[col].mode()[0])\nfor col in df.select_dtypes(include='number'):\n    df[col] = df[col].fillna(df[col].median())\n```\n\n### Time Series Resampling\n\n```python\ndaily = (\n    df.set_index('timestamp')\n    .resample('D')\n    .agg({'revenue': 'sum', 'sessions': 'count'})\n    .fillna(0)\n)\n```\n\n### Pivot Table\n\n```python\npivot = df.pivot_table(\n    values='revenue',\n    index='region',\n    columns='product_line',\n    aggfunc='sum',\n    fill_value=0,\n    margins=True,\n)\n```\n\n### Memory Optimization\n\n```python\n# Downcast numerics and convert low-cardinality strings to categorical\ndf['category'] = df['category'].astype('category')\ndf['count'] = pd.to_numeric(df['count'], downcast='integer')\ndf['score'] = pd.to_numeric(df['score'], downcast='float')\nprint(df.memory_usage(deep=True).sum() / 1e6, \"MB after optimization\")\n```\n\n## Constraints\n\n### MUST DO\n- Use vectorized operations instead of loops\n- Set appropriate dtypes (categorical for low-cardinality strings)\n- Check memory usage with `.memory_usage(deep=True)`\n- Handle missing values explicitly (don't silently drop)\n- Use method chaining for readability\n- Preserve index integrity through operations\n- Validate data quality before and after transformations\n- Use `.copy()` when modifying subsets to avoid SettingWithCopyWarning\n\n### MUST NOT DO\n- Iterate over DataFrame rows with `.iterrows()` unless absolutely necessary\n- Use chained indexing (`df['A']['B']`) — use `.loc[]` or `.iloc[]`\n- Ignore SettingWithCopyWarning messages\n- Load entire large datasets without chunking\n- Use deprecated methods (`.ix`, `.append()` — use `pd.concat()`)\n- Convert to Python lists for operations possible in pandas\n- Assume data is clean without validation\n\n## Output Templates\n\nWhen implementing pandas solutions, provide:\n1. Code with vectorized operations and proper indexing\n2. Comments explaining complex transformations\n3. Memory/performance considerations if dataset is large\n4. Data validation checks (dtypes, nulls, shapes)\n\n[Documentation](https://jeffallan.github.io/claude-skills/skills/data-ml/pandas-pro/)","author":"@Jeffallan","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/Jeffallan/claude-skills/tree/main/skills/pandas-pro","license":"MIT","category":"coding","lang":"en","tokens":1262,"stars":0,"calls30d":0,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"references/aggregation-groupby.md","size":13206,"sha256":"d71f9e011ebbcc62e4b695932c8e526cfe45b37ec05088bf2995a6f49f26a68d"},{"path":"references/data-cleaning.md","size":12969,"sha256":"99468b768f3bfe7a6efb24999462d80791292861c3037ca46b8073d2828490f4"},{"path":"references/dataframe-operations.md","size":9667,"sha256":"ea3807160696538f33abda69d557f2810bdff7e746f01673e94f1a349dca3e3e"},{"path":"references/merging-joining.md","size":13517,"sha256":"f51f06377908a6aaa9ed498a673d993826bd6d642e3d6af2c26878dd9c80bb87"},{"path":"references/performance-optimization.md","size":15068,"sha256":"a34ad5df2cba5465ceea51ed61191b0eaf9adf38c65bc2ef18aacd21ca5ecb48"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[{"code":"code.eval","kind":"dangerous-code","where":"references/performance-optimization.md:379","excerpt":"eval(","message":"evaluates code at runtime","severity":"warn"}],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":["jeffallan.github.io"]}}