원클릭으로
data-prep
Load, validate, and aggregate transaction data for customer-base audit
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Load, validate, and aggregate transaction data for customer-base audit
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
| name | data-prep |
| description | Load, validate, and aggregate transaction data for customer-base audit |
First step of any customer-base audit. Invoke when the user provides raw transaction data (CSV, Parquet, Excel).
A data file with at minimum: customer identifier, transaction date, transaction amount. Optional: profit/margin, product category, order ID, units.
import polars as pl
from pathlib import Path
path = Path("DATA_FILE") # user provides this
if path.suffix == ".parquet":
df = pl.read_parquet(path)
elif path.suffix == ".csv":
df = pl.read_csv(path, try_parse_dates=True)
elif path.suffix in (".xlsx", ".xls"):
df = pl.read_excel(path)
Map the user's column names to canonical roles. Look for these patterns:
| Role | Common names |
|---|---|
| customer_id | customer_id, cust_id, user_id, buyer_id, client_id |
| date | date, order_date, transaction_date, purchase_date |
| spend | spend, revenue, amount, sales, value, total_spend |
| profit | profit, total_profit, margin_dollars, gross_profit |
| category | category, product_category, product, sku, item |
| order_id | order_id, transaction_id, invoice_id |
Required: customer_id, date, spend. If ambiguous, ask the user.
Rename columns to canonical names before proceeding:
df = df.rename({"user_column": "customer_id", "user_date": "date", ...})
Run these checks. STOP on errors. Warn on warnings.
# Nulls in required columns (ERROR)
for col in ["customer_id", "date", "spend"]:
null_count = df[col].null_count()
if null_count > 0:
print(f"ERROR: {null_count} nulls in '{col}'")
# Negative spend (WARNING)
neg_spend = df.filter(pl.col("spend") < 0).height
if neg_spend > 0:
print(f"WARNING: {neg_spend} rows with negative spend (returns?)")
# Date range (WARNING if < 90 days)
span = (df["date"].max() - df["date"].min()).days
if span < 90:
print(f"WARNING: Only {span} days of data. Most analyses need >= 1 year.")
# Duplicate order IDs (WARNING -- may indicate line-item data)
if "order_id" in df.columns:
n_unique = df["order_id"].n_unique()
if n_unique < df.height:
print(f"WARNING: {df.height - n_unique} duplicate order_ids (line-item data?)")
If data has duplicate order_ids (line-item level), collapse to one row per order:
orders = df.group_by("order_id").agg(
pl.col("customer_id").first(),
pl.col("date").first(),
pl.col("spend").sum(),
pl.col("profit").sum(), # if profit column exists
pl.col("category").first(), # if category column exists
)
If no order_id column, each row is already an order.
Auto-detect granularity: quarterly if data spans >= 2 years, monthly otherwise.
span_years = (df["date"].max() - df["date"].min()).days / 365
granularity = "quarterly" if span_years >= 2 else "monthly"
if granularity == "quarterly":
orders = orders.with_columns(
(pl.col("date").dt.year().cast(pl.Utf8) + "-Q" + pl.col("date").dt.quarter().cast(pl.Utf8)).alias("period")
)
elif granularity == "monthly":
orders = orders.with_columns(
pl.col("date").dt.strftime("%Y-%m").alias("period")
)
cust_periods = orders.group_by("customer_id", "period").agg(
pl.len().alias("num_transactions"),
pl.col("spend").sum().alias("total_spend"),
pl.col("profit").sum().alias("total_profit"), # if profit exists
)
Each customer's cohort = the period of their first purchase:
cohorts = orders.group_by("customer_id").agg(
pl.col("period").sort().first().alias("cohort")
)
orders = orders.join(cohorts, on="customer_id")
orders.write_parquet("output/prepared_data.parquet")
cust_periods.write_parquet("output/customer_summary.parquet")
${CLAUDE_PLUGIN_ROOT}/references/methodology.mdTurn completed audit outputs into an executive-ready document (Word/PDF) organized by insight, not by lens -- Pyramid Principle, SCQA, action titles, embedded exhibits
Complete customer-base audit orchestrator -- runs all lenses with parallel sub-agents and review
Lens 4 -- Compare two acquisition cohorts side-by-side using left-aligned analysis
Lens 3 -- Track a single cohort's behavior over time (activity, frequency, value decay)
Lens 5 -- Assess overall customer base health via C3 chart, acquisition flow, and repeat rates
Lens 1 -- Analyze customer heterogeneity via profit decomposition, distributions, and deciles