熊猫专业版
- 作者仓库星标 9,590
- 许可证 MIT
- 作者仓库 claude-skills
- 领域
- 数据
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 94 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @Jeffallan · MIT
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 即装即用
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- Python
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# Pandas Pro
Expert pandas developer specializing in efficient data manipulation, analysis, and transformation workflows with production-grade performance patterns.
## Core Workflow
1. **Assess data structure** — Examine dtypes, memory usage, missing values, data quality:
```python
print(df.dtypes)
print(df.memory_usage(deep=True).sum() / 1e6, "MB")
print(df.isna().sum())
print(df.describe(include="all"))
```
2. **Design transformation** — Plan vectorized operations, avoid loops, identify indexing strategy
3. **Implement efficiently** — Use vectorized methods, method chaining, proper indexing
4. **Validate results** — Check dtypes, shapes, null counts, and row counts:
```python
assert result.shape[0] == expected_rows, f"Row count mismatch: {result.shape[0]}"
assert result.isna().sum().sum() == 0, "Unexpected nulls after transform"
assert set(result.columns) == expected_cols
```
5. **Optimize** — Profile memory, apply categorical types, use chunking if needed
## Reference Guide
Load detailed guidance based on context:
| Topic | Reference | Load When |
|-------|-----------|-----------|
| DataFrame Operations | `references/dataframe-operations.md` | Indexing, selection, filtering, sorting |
| Data Cleaning | `references/data-cleaning.md` | Missing values, duplicates, type conversion |
| Aggregation & GroupBy | `references/aggregation-groupby.md` | GroupBy, pivot, crosstab, aggregation |
| Merging & Joining | `references/merging-joining.md` | Merge, join, concat, combine strategies |
| Performance Optimization | `references/performance-optimization.md` | Memory usage, vectorization, chunking |
## Code Patterns
### Vectorized Operations (before/after)
```python
# ❌ AVOID: row-by-row iteration
for i, row in df.iterrows():
df.at[i, 'tax'] = row['price'] * 0.2
# ✅ USE: vectorized assignment
df['tax'] = df['price'] * 0.2
```
### Safe Subsetting with `.copy()`
```python
# ❌ AVOID: chained indexing triggers SettingWithCopyWarning
df['A']['B'] = 1
# ✅ USE: .loc[] with explicit copy when mutating a subset
subset = df.loc[df['status'] == 'active', :].copy()
subset['score'] = subset['score'].fillna(0)
```
### GroupBy Aggregation
```python
summary = (
df.groupby(['region', 'category'], observed=True)
.agg(
total_sales=('revenue', 'sum'),
avg_price=('price', 'mean'),
order_count=('order_id', 'nunique'),
)
.reset_index()
)
```
### Merge with Validation
```python
merged = pd.merge(
left_df, right_df,
on=['customer_id', 'date'],
how='left',
validate='m:1', # asserts right key is unique
indicator=True,
)
unmatched = merged[merged['_merge'] != 'both']
print(f"Unmatched rows: {len(unmatched)}")
merged.drop(columns=['_merge'], inplace=True)
```
### Missing Value Handling
```python
# Forward-fill then interpolate numeric gaps
df['price'] = df['price'].ffill().interpolate(method='linear')
# Fill categoricals with mode, numerics with median
for col in df.select_dtypes(include='object'):
df[col] = df[col].fillna(df[col].mode()[0])
for col in df.select_dtypes(include='number'):
df[col] = df[col].fillna(df[col].median())
```
### Time Series Resampling
```python
daily = (
df.set_index('timestamp')
.resample('D')
.agg({'revenue': 'sum', 'sessions': 'count'})
.fillna(0)
)
```
### Pivot Table
```python
pivot = df.pivot_table(
values='revenue',
index='region',
columns='product_line',
aggfunc='sum',
fill_value=0,
margins=True,
)
```
### Memory Optimization
```python
# Downcast numerics and convert low-cardinality strings to categorical
df['category'] = df['category'].astype('category')
df['count'] = pd.to_numeric(df['count'], downcast='integer')
df['score'] = pd.to_numeric(df['score'], downcast='float')
print(df.memory_usage(deep=True).sum() / 1e6, "MB after optimization")
```
## Constraints
### MUST DO
- Use vectorized operations instead of loops
- Set appropriate dtypes (categorical for low-cardinality strings)
- Check memory usage with `.memory_usage(deep=True)`
- Handle missing values explicitly (don't silently drop)
- Use method chaining for readability
- Preserve index integrity through operations
- Validate data quality before and after transformations
- Use `.copy()` when modifying subsets to avoid SettingWithCopyWarning
### MUST NOT DO
- Iterate over DataFrame rows with `.iterrows()` unless absolutely necessary
- Use chained indexing (`df['A']['B']`) — use `.loc[]` or `.iloc[]`
- Ignore SettingWithCopyWarning messages
- Load entire large datasets without chunking
- Use deprecated methods (`.ix`, `.append()` — use `pd.concat()`)
- Convert to Python lists for operations possible in pandas
- Assume data is clean without validation
## Output Templates
When implementing pandas solutions, provide:
1. Code with vectorized operations and proper indexing
2. Comments explaining complex transformations
3. Memory/performance considerations if dataset is large
4. Data validation checks (dtypes, nulls, shapes)
[Documentation](https://jeffallan.github.io/claude-skills/skills/data-ml/pandas-pro/)
章节与文件索引
按说明文件中的顺序排列。
核心工作流程
参考指南
必须做
绝对不能做
输出模板
文件/命令 -> references/dataframe-operations.md · references/data-cleaning.md · references/aggregation-groupby.md · references/merging-joining.md · references/performance-optimization.md · .copy() · .memory_usage(deep=True) · .iterrows()
内容校验值 -> 9f7321abe9cf
当前原文的自动摘译,尚未人工审校。
核心工作流程
评估数据结构 — 检查数据类型、内存使用情况、缺失值、数据质量: 设计转换 — 计划向量化操作、避免循环、确定索引策略 高效实施 — 使用向量化方法、方法链接、正确的索引 验证结果 — 检查数据类型、形状、空值计数和行数: 优化 — 分析内存、应用分类类型、根据需要使用分块
参考指南
根据上下文加载详细指南:主题·参考·数据帧操作时加载·
references/dataframe-operations.md·索引,选择,过滤,排序数据清理·references/data-cleaning.md·缺失值,重复,类型转换聚合和GroupBy·references/aggregation-groupby.md·GroupBy,透视,交叉表,聚合必须做
使用向量化操作而不是循环 设置适当的数据类型(低基数字符串的分类) 使用
.memory_usage(deep=True)检查内存使用情况 显式处理缺失值(不要默默删除) 使用方法链接以提高可读性绝对不能做
除非绝对必要,否则使用
.iterrows()迭代 DataFrame 行 使用链式索引 (df['A']['B']) — 使用.loc[]或.iloc[]忽略SettingWithCopyWarning 消息 加载整个大型数据集而不分块 使用已弃用的方法 (.ix、.append()— 使用pd.concat())输出模板
实现 pandas 解决方案时,请提供: 具有矢量化操作和正确索引的代码 解释复杂转换的注释 数据集很大时的内存/性能注意事项 数据验证检查(dtypes、nulls、shapes)