用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/UitbreidenOS/UitKit --skill pandas-polars命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
Guidelines and instructions for Agent execution state rollback rules
Guidelines and instructions for Agent execution step counters limits
Guidelines and instructions for Agent execution timeout limits setups
基于 SOC 职业分类
| name | pandas-polars |
| description | Pandas and Polars data manipulation: filtering, groupby, joins, time series, performance optimization |
import pandas as pd
import numpy as np
# Never use iterrows() — vectorize instead
# Bad:
for idx, row in df.iterrows():
df.at[idx, 'tax'] = row['price'] * 0.2
# Good:
df['tax'] = df['price'] * 0.2
# Use .loc for label-based access, .iloc for position-based
# Never chain without assignment — causes SettingWithCopyWarning
df.loc[df['status'] == 'active', 'flag'] = True
# Categorical dtype for low-cardinality string columns (massive memory saving)
df['country'] = df['country'].astype('category')
# Downcasting numeric types to reduce memory
df['quantity'] = pd.to_numeric(df['quantity'], downcast='integer')
df['price'] = pd.to_numeric(df['price'], downcast='float')
# Groupby with multiple aggregations
summary = (
df.groupby(['region', 'category'])
.agg(
total_revenue=('revenue', 'sum'),
order_count=('order_id', 'nunique'),
avg_order_value=('revenue', 'mean'),
)
.reset_index()
.sort_values('total_revenue', ascending=False)
)
# Always specify how= explicitly — never rely on default (inner)
result = pd.merge(
orders,
customers,
on='customer_id',
how='left', # explicit
validate='m:1', # validates cardinality — raises if violated
suffixes=('_order', '_customer')
)
Use Polars when:
import polars as pl
# Lazy API — queries are optimized before execution
result = (
pl.scan_parquet("orders.parquet") # Lazy scan — no data loaded yet
.filter(pl.col("status") == "completed")
.group_by(["region", "category"])
.agg([
pl.col("revenue").sum().alias("total_revenue"),
pl.col("order_id").n_unique().alias("order_count"),
pl.col("revenue").mean().alias("avg_order_value"),
])
.sort("total_revenue", descending=True)
.collect() # Execute now
)
# Polars: no SettingWithCopyWarning, no chained indexing
df = df.with_columns([
(pl.col("price") * 0.2).alias("tax"),
pl.col("name").str.to_uppercase().alias("name_upper"),
pl.when(pl.col("quantity") > 10)
.then(pl.lit("bulk"))
.otherwise(pl.lit("standard"))
.alias("order_type"),
])
def validate_orders(df: pd.DataFrame) -> None:
assert df['order_id'].notna().all(), "order_id has nulls"
assert df['order_id'].is_unique, "order_id has duplicates"
assert (df['amount'] >= 0).all(), "amount has negative values"
assert df['status'].isin(['pending', 'completed', 'cancelled']).all(), "invalid status values"
assert pd.to_datetime(df['created_at'], errors='coerce').notna().all(), "created_at has invalid dates"
# Read
df = pd.read_parquet("data.parquet", columns=['id', 'name', 'amount']) # Column selection at read time
df = pd.read_csv("data.csv", dtype={'id': str}, parse_dates=['created_at'])
# Write — always use Parquet over CSV for large datasets
df.to_parquet("output.parquet", index=False, compression='snappy')
User: Clean a raw orders CSV: fix dtypes, remove duplicates, handle nulls, add derived columns (revenue_after_tax, order_size_bucket), and output a validated Parquet file.
Expected output:
dtype= and parse_dates=order_id rows (keep last)quantity → 0, discount → 0.0, drop rows where customer_id is nullrevenue_after_tax = price * quantity * (1 - discount) * 0.8order_size_bucket = 'small'/<100, 'medium'/100–1000, 'large'/>1000