debug:pandas
Debug Pandas issues systematically. Use when encountering DataFrame errors, SettingWithCopyWarning, KeyError on column access, merge and join mismatches with unexpected NaN values, memory errors with large DataFrames, dtype conversion issues, index alignment problems, or any data manipulation errors in Python data analysis workflows.
What this skill does
# Pandas Debugging Guide
A systematic approach to debugging Pandas DataFrames and operations using the OILER framework (Orient, Investigate, Locate, Experiment, Reflect).
## Common Error Patterns
### 1. SettingWithCopyWarning
**Symptom:** Warning message about setting values on a copy of a slice.
**Cause:** Modifying a view of a DataFrame rather than a copy. Pandas cannot guarantee whether the operation affects the original data.
**Solution:**
```python
# BAD - triggers warning
df_subset = df[df['col'] > 5]
df_subset['new_col'] = 10 # Warning!
# GOOD - explicit copy
df_subset = df[df['col'] > 5].copy()
df_subset['new_col'] = 10 # Safe
# GOOD - use .loc for in-place modification
df.loc[df['col'] > 5, 'new_col'] = 10
```
### 2. KeyError on Column Access
**Symptom:** `KeyError: 'column_name'`
**Cause:** Column doesn't exist due to typo, incorrect capitalization, or column was never created.
**Solution:**
```python
# Check available columns
print(df.columns.tolist())
# Check for whitespace in column names
print([repr(c) for c in df.columns])
# Strip whitespace from all column names
df.columns = df.columns.str.strip()
# Case-insensitive column access
col_lower = {c.lower(): c for c in df.columns}
actual_col = col_lower.get('mycolumn'.lower())
```
### 3. Merge/Join Mismatches
**Symptom:** Unexpected row counts after merge, NaN values, or `MergeError`.
**Cause:** Mismatched column names, different dtypes, or unexpected duplicates.
**Solution:**
```python
# Before merging - inspect both DataFrames
print(f"Left shape: {df1.shape}, Right shape: {df2.shape}")
print(f"Left key dtype: {df1['key'].dtype}, Right: {df2['key'].dtype}")
print(f"Left key unique: {df1['key'].nunique()}, Right: {df2['key'].nunique()}")
# Check for duplicates in merge keys
print(f"Left duplicates: {df1['key'].duplicated().sum()}")
print(f"Right duplicates: {df2['key'].duplicated().sum()}")
# Explicit merge with indicator
result = df1.merge(df2, on='key', how='outer', indicator=True)
print(result['_merge'].value_counts())
```
### 4. Memory Errors with Large DataFrames
**Symptom:** `MemoryError` or system becomes unresponsive.
**Cause:** DataFrame too large for available RAM.
**Solution:**
```python
# Check current memory usage
print(df.info(memory_usage='deep'))
print(df.memory_usage(deep=True).sum() / 1024**2, 'MB')
# Optimize dtypes
def optimize_dtypes(df):
for col in df.select_dtypes(include=['int64']).columns:
df[col] = pd.to_numeric(df[col], downcast='integer')
for col in df.select_dtypes(include=['float64']).columns:
df[col] = pd.to_numeric(df[col], downcast='float')
for col in df.select_dtypes(include=['object']).columns:
if df[col].nunique() / len(df) < 0.5:
df[col] = df[col].astype('category')
return df
# Read in chunks
chunks = pd.read_csv('large_file.csv', chunksize=100000)
for chunk in chunks:
process(chunk)
# Use PyArrow backend (Pandas 2.0+)
df = pd.read_csv('file.csv', dtype_backend='pyarrow')
```
### 5. dtype Conversion Issues
**Symptom:** `ValueError` during type conversion, unexpected NaN values.
**Cause:** Non-numeric strings in numeric columns, mixed types.
**Solution:**
```python
# Identify problematic values
def find_non_numeric(series):
mask = pd.to_numeric(series, errors='coerce').isna() & series.notna()
return series[mask].unique()
print(find_non_numeric(df['numeric_col']))
# Safe conversion with error handling
df['numeric_col'] = pd.to_numeric(df['numeric_col'], errors='coerce')
# Check for mixed types
print(df['col'].apply(type).value_counts())
# Convert with explicit handling
df['date_col'] = pd.to_datetime(df['date_col'], errors='coerce', format='%Y-%m-%d')
```
### 6. Index Alignment Problems
**Symptom:** Unexpected NaN values after operations, incorrect calculations.
**Cause:** Pandas aligns operations by index, misaligned indices cause NaN.
**Solution:**
```python
# Check index alignment
print(f"Index 1: {df1.index[:5].tolist()}")
print(f"Index 2: {df2.index[:5].tolist()}")
# Reset index for array-like operations
result = df1.reset_index(drop=True) + df2.reset_index(drop=True)
# Use .values for numpy-style operations (bypasses alignment)
result = df1['col'].values + df2['col'].values
# Check for duplicate indices
print(f"Duplicate indices: {df.index.duplicated().sum()}")
```
### 7. TypeError: 'DataFrame' object is not callable
**Symptom:** `TypeError` when accessing DataFrame.
**Cause:** Using parentheses `()` instead of brackets `[]`.
**Solution:**
```python
# BAD
df('column_name') # TypeError!
# GOOD
df['column_name']
df.loc[0, 'column_name']
```
### 8. AttributeError on Column Access
**Symptom:** `AttributeError` when using dot notation.
**Cause:** Column name contains spaces, special characters, or conflicts with DataFrame methods.
**Solution:**
```python
# BAD - fails for special names
df.my column # SyntaxError
df.count # Returns method, not column named 'count'
# GOOD - always works
df['my column']
df['count']
```
## Debugging Tools
### Essential Inspection Commands
```python
# Overview of DataFrame
df.info() # Columns, dtypes, non-null counts, memory
df.describe() # Statistical summary
df.shape # (rows, columns)
df.dtypes # Column data types
# Sample data
df.head(10) # First 10 rows
df.tail(10) # Last 10 rows
df.sample(10) # Random 10 rows
# Column inspection
df.columns.tolist() # All column names as list
df['col'].unique() # Unique values
df['col'].value_counts() # Value frequency
df['col'].isna().sum() # Missing value count
# Memory usage
df.memory_usage(deep=True) # Per-column memory in bytes
df.memory_usage(deep=True).sum() / 1024**2 # Total MB
```
### Display Options
```python
# Show all columns
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
# Show all rows (use carefully!)
pd.set_option('display.max_rows', 100)
# Show full content of columns
pd.set_option('display.max_colwidth', None)
# Float precision
pd.set_option('display.precision', 4)
# Reset all options
pd.reset_option('all')
```
### Pandas-Log for Chain Debugging
```python
# Install: pip install pandas-log
import pandas_log
# Wrap operations with logging
with pandas_log.enable():
result = (df
.query('col > 5')
.groupby('category')
.agg({'value': 'sum'})
)
# Outputs: rows/columns affected at each step
```
## The Four Phases (OILER Framework)
### Phase 1: Orient
Understand the problem before diving in.
```python
# What is the error message?
# What operation triggered it?
# What is the expected vs actual behavior?
# Quick state check
print(f"Shape: {df.shape}")
print(f"Columns: {df.columns.tolist()}")
print(f"Dtypes:\n{df.dtypes}")
print(f"Head:\n{df.head(3)}")
```
### Phase 2: Investigate
Gather information systematically.
```python
# Check data quality
def investigate_df(df):
print("=== DataFrame Investigation ===")
print(f"Shape: {df.shape}")
print(f"\nMissing values:\n{df.isna().sum()}")
print(f"\nDtypes:\n{df.dtypes}")
print(f"\nDuplicate rows: {df.duplicated().sum()}")
print(f"\nMemory: {df.memory_usage(deep=True).sum() / 1024**2:.2f} MB")
# Check for mixed types in object columns
for col in df.select_dtypes(include=['object']).columns:
types = df[col].apply(type).value_counts()
if len(types) > 1:
print(f"\nMixed types in '{col}':\n{types}")
investigate_df(df)
```
### Phase 3: Locate
Narrow down the source of the problem.
```python
# For chained operations - break them apart
# BAD - hard to debug
result = df.query('x > 5').groupby('cat').agg({'val': 'sum'}).reset_index()
# GOOD - step by step
step1 = df.query('x > 5')
print(f"After filter: {step1.shape}")
step2 = step1.groupby('cat')
print(f"Groups:Related in Ads & Marketing
ads
IncludedMulti-platform paid advertising audit and optimization skill. Analyzes Google, Meta, YouTube, LinkedIn, TikTok, Microsoft, and Apple Ads. 250+ checks with scoring, parallel agents, industry templates, and AI creative generation.
banana
IncludedAI image generation Creative Director powered by Google Gemini Nano Banana models. Use this skill for ANY request involving image creation, editing, visual asset production, or creative direction. Triggers on: generate an image, create a photo, edit this picture, design a logo, make a banner, visual for my anything, and all /banana commands. Handles text-to-image, image editing, multi-turn creative sessions, batch workflows, and brand presets.
rpg-migration-analyzer
IncludedAnalyzes legacy RPG (Report Program Generator) programs from AS/400 and IBM i systems for migration to modern Java applications. Extracts business logic from RPG III/IV/ILE source code, identifies data structures (D-specs), file operations (F-specs), program dependencies (CALLB/CALLP), and converts RPG constructs to Java equivalents. Generates migration reports, complexity estimates, and Java implementation strategies with POJO classes, JPA entities, and service methods. Use when modernizing AS/400 or IBM i legacy systems, analyzing RPG source files (.rpg, .rpgle, .RPGLE), converting RPG to Java, mapping data specifications to Java classes, planning legacy system migration, or when user mentions RPG analysis, Report Program Generator, RPG III/IV/ILE, AS/400 modernization, IBM i migration, packed decimal conversion, or mainframe application rewrite.
brand-library-architect
IncludedBuild a complete brand library for a product — visual asset render pipeline, brand documentation set (BRAND, COPY, MANIFESTO, BIOS, FAQ, GLOSSARY, TONE, PRICING), open-source convention files (README, CONTRIBUTING, SECURITY, CODE_OF_CONDUCT), and a self-contained press kit. This skill should be used when the user asks to "build a brand library / brand kit / press kit / brand assets" for a product, "set up a brand library workflow," "create a positioning manifesto plus visual identity," or any combination of brand documentation + visual asset pipeline. Apply phase-by-phase or run end-to-end. Templates are product-agnostic and use {{TOKEN}} placeholders the skill prompts the user to fill.
writing-tech-post
IncludedAuthors engineering blog posts end-to-end: launch deep-dives, incident postmortems, architecture migrations, performance case studies, tutorials, AI/agent system writeups, security disclosures, and research-to-product translations. Picks the correct archetype, plans the abstraction ladder, enforces an evidence cadence (diagrams, benchmarks, profiles, traces, code, ablations), tunes voice against publisher house styles (Datadog, Vercel, GitHub, AWS, Meta, Cloudflare, Jane Street), and runs a pre-publish gate for narrative momentum and disclosure ethics. Use when drafting a new engineering post, restructuring a draft that feels flat, deciding which evidence form belongs where, validating that depth and product context are balanced, or preparing a postmortem, migration, or performance narrative for external publication. Do not use for API reference documentation, README authoring, marketing copy, release notes, generic SEO content, ghost-written executive thought leadership, or non-engineering long-form essays.
blog-google
IncludedGoogle API integration for blog performance: PageSpeed Insights, CrUX Core Web Vitals with 25-week history, Search Console performance, URL Inspection, Indexing API, GA4 organic traffic, NLP entity analysis for E-E-A-T, YouTube video search for embedding, and Google Ads Keyword Planner. Progressive feature availability based on credential tier (API key, OAuth/service account, GA4, Ads). Shares config with claude-seo at ~/.config/claude-seo/google-api.json. Use when user says "google data", "page speed", "core web vitals", "search console", "indexation", "GA4", "keyword research", "nlp entities", "blog performance", "youtube search", "google api setup".