Pandas
by @ivangdavila
Analyze, transform, and clean DataFrames with efficient patterns for filtering, grouping, merging, and pivoting.
clawhub install pandasπ About This Skill
name: Pandas slug: pandas version: 1.0.1 homepage: https://clawic.com/skills/pandas description: Analyze, transform, and clean DataFrames with efficient patterns for filtering, grouping, merging, and pivoting. metadata: {"clawdbot":{"emoji":"πΌ","requires":{"bins":["python3"]},"os":["linux","darwin","win32"]}}
Setup
On first use, create ~/pandas/ and read setup.md for initialization. User preferences are stored in ~/pandas/memory.md β users can view or edit this file anytime.
When to Use
User needs to work with tabular data in Python. Agent handles DataFrame operations, data cleaning, aggregations, merges, pivots, and exports.
Architecture
Memory lives in ~/pandas/. See memory-template.md for structure.
~/pandas/
βββ memory.md # User preferences and common patterns
βββ snippets/ # Saved code patterns (optional)
Quick Reference
| Topic | File |
|-------|------|
| Setup process | setup.md |
| Memory template | memory-template.md |
Core Rules
1. Use Vectorized Operations
for loops over DataFrame rows.apply() only when vectorized alternatives don't existdf['col'].str.method() over apply(lambda x: x.method())2. Chain Methods for Readability
# Good: method chaining
result = (df
.query('age > 30')
.groupby('city')
.agg({'salary': 'mean'})
.reset_index())Bad: intermediate variables everywhere
filtered = df[df['age'] > 30]
grouped = filtered.groupby('city')
result = grouped.agg({'salary': 'mean'}).reset_index()
3. Handle Missing Data Explicitly
df.isna().sum() before analysisdropna(), fillna(), or interpolation4. Use Categorical for Repeated Strings
# Memory savings for columns with few unique values
df['status'] = df['status'].astype('category')
df['country'] = df['country'].astype('category')
5. Merge with Validation
# Always specify how and validate
result = pd.merge(
df1, df2,
on='id',
how='left',
validate='m:1' # Many-to-one: catch unexpected duplicates
)
6. Prefer query() for Complex Filters
# Readable
df.query('age > 30 and city == "NYC" and salary < 100000')Hard to read
df[(df['age'] > 30) & (df['city'] == 'NYC') & (df['salary'] < 100000)]
7. Set Index When Appropriate
# Faster lookups, cleaner merges
df = df.set_index('user_id')
user_data = df.loc[12345] # O(1) lookup
Common Traps
.loc[] for assignment: df.loc[mask, 'col'] = valueiterrows() with vectorized ops or apply()dtype in read_csv(): pd.read_csv(f, dtype={'id': 'int32'})print(f"Before: {len(df1)}, After: {len(result)}")reset_index() after groupby() to get clean DataFramedf['a']['b'] fails silently; use df.loc[:, ['a', 'b']]Security & Privacy
Data storage:
~/pandas/memory.mdThis skill does NOT:
~/pandas/ and the working directoryUser control:
cat ~/pandas/memory.mdrm -rf ~/pandas/Related Skills
Install withclawhub install if user confirms:
data-analysis β general data analysis patternscsv β CSV file handlingsql β database queriesexcel-xlsx β Excel file operationsFeedback
clawhub star pandasclawhub syncβ‘ When to Use
User needs to work with tabular data in Python. Agent handles DataFrame operations, data cleaning, aggregations, merges, pivots, and exports.
βοΈ Configuration
On first use, create ~/pandas/ and read setup.md for initialization. User preferences are stored in ~/pandas/memory.md β users can view or edit this file anytime.