技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
Pandas【数据与研究】Analyze, transform, and clean DataFrames with efficient patterns for filtering, grouping, merging, and pivoting.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
On first use, create ~/Clawic/data/pandas/ and read setup.md for initialization. User preferences are stored in ~/Clawic/data/pandas/memory.md — users can view or edit this file anytime.
User needs to work with tabular data in Python. Agent handles DataFrame operations, data cleaning, aggregations, merges, pivots, and exports.
Memory lives in ~/Clawic/data/pandas/. See memory-template.md for structure.
~/Clawic/data/pandas/
├── memory.md # User preferences and common patterns
└── snippets/ # Saved code patterns (optional)
| Topic | File |
|---|---|
| Setup process | setup.md |
| Memory template | memory-template.md |
for loops over DataFrame rows.apply() only when vectorized alternatives don't existdf['col'].str.method() over apply(lambda x: x.method())# 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()
df.isna().sum() before analysisdropna(), fillna(), or interpolation# Memory savings for columns with few unique values
df['status'] = df['status'].astype('category')
df['country'] = df['country'].astype('category')
# Always specify how and validate
result = pd.merge(
df1, df2,
on='id',
how='left',
validate='m:1' # Many-to-one: catch unexpected duplicates
)
# Readable
df.query('age > 30 and city == "NYC" and salary < 100000')
# Hard to read
df[(df['age'] > 30) & (df['city'] == 'NYC') & (df['salary'] < 100000)]
# Faster lookups, cleaner merges
df = df.set_index('user_id')
user_data = df.loc[12345] # O(1) lookup
.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']]Data storage:
~/Clawic/data/pandas/memory.mdThis skill does NOT:
~/Clawic/data/pandas/ and the working directoryUser control:
cat ~/Clawic/data/pandas/memory.mdrm -rf ~/Clawic/data/pandas/More Clawic skills, get them at https://clawic.com/skills/ (install if the user confirms):
data-analysis — general data analysis patternscsv — CSV file handlingsql — database queriesexcel-xlsx — Excel file operations