Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Systematic data cleaning workflows for research datasets
.claude/skills/brycewang-stanford-data-cleaning-pipeline/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-07 | ✗→✓ | ▲ Improved | 44% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 64% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 89% | 0% |
| case-14 | ✗→✓ | ▲ Improved | 90% | 0% |
| case-17 | ✗→✓ | ▲ Improved | 112% | 0% |
A skill for building systematic, reproducible data cleaning pipelines for research datasets. Covers common data quality issues, step-by-step cleaning workflows, handling missing values, detecting and treating outliers, validating data integrity, and documenting cleaning decisions for reproducibility.
Data cleaning should follow a consistent, documented order. Each step builds on the previous one, and the entire pipeline should be scripted for reproducibility.
Data Cleaning Pipeline (recommended order):
1. Initial Assessment
- Load data, check dimensions, inspect dtypes
- Generate summary statistics and missing value report
- Identify structural issues (merged cells, inconsistent delimiters)
2. Structural Fixes
- Standardize column names (snake_case, no spaces)
- Fix data types (strings to numbers, dates, categories)
- Split or merge columns as needed
- Remove completely empty rows/columns
3. Deduplication
- Identify exact duplicates
- Identify near-duplicates (fuzzy matching)
- Decide keep-first, keep-last, or merge strategy
4. Missing Value Treatment
- Classify missingness mechanism (MCAR, MAR, MNAR)
- Apply appropriate imputation or exclusion strategy
- Document and justify missing data decisions
5. Outlier Detection and Treatment
- Statistical methods (IQR, z-score, Mahalanobis)
- Domain-based validation (impossible values)
- Decide: correct, cap, remove, or keep with flag
6. Consistency Checks
- Cross-field validation (age vs birth date)
- Range validation (0-100 for percentages)
- Referential integrity (foreign keys exist)
7. Documentation and Export
- Log all changes with before/after counts
- Export cleaned dataset with version number
- Save cleaning script for reproducibilitypythonimport pandas as pd import numpy as np def generate_quality_report(df): """ Generate a comprehensive data quality report. Run this BEFORE any cleaning to establish a baseline. """ report = { "dimensions": f"{df.shape[0]} rows x {df.shape[1]} columns", "memory_usage": f"{df.memory_usage(deep=True).sum() / 1e6:.1f} MB", "duplicate_rows": df.duplicated().sum(), } col_report = [] for col in df.columns: info = { "column": col, "dtype": str(df[col].dtype), "missing_count": df[col].isna().sum(), "missing_pct": f"{df[col].isna().mean() * 100:.1f}%", "unique_values": df[col].nunique(), "sample_values": str(df[col].dropna().head(3).tolist()), } if pd.api.types.is_numeric_dtype(df[col]): info["min"] = df[col].min() info["max"] = df[col].max() info["mean"] = df[col].mean() info["std"] = df[col].std() col_report.append(info) report["columns"] = col_report return report
Missing data mechanisms (Rubin's classification):
MCAR (Missing Completely At Random):
- Missingness is unrelated to any variable
- Example: Lab samples randomly lost during transport
- Test: Little's MCAR test, compare distributions
- Safe to: Listwise delete if < 5% missing
MAR (Missing At Random):
- Missingness depends on observed variables but not the missing value
- Example: Younger participants skip income questions more often
- Test: Compare missingness patterns across groups
- Best approach: Multiple imputation, regression imputation
MNAR (Missing Not At Random):
- Missingness depends on the unobserved value itself
- Example: High-income people refuse to report income
- Cannot be tested directly from the data
- Requires: Sensitivity analysis, selection models, domain expertisepythonfrom sklearn.impute import SimpleImputer, KNNImputer def impute_missing_values(df, numeric_strategy="median", categorical_strategy="mode"): """ Apply appropriate imputation strategies by column type. For research data, prefer: - Median for skewed numeric data - Mean for normally distributed numeric data - Mode for categorical data - KNN for multivariate patterns - Multiple imputation for inference (use statsmodels or mice) """ numeric_cols = df.select_dtypes(include=[np.number]).columns categorical_cols = df.select_dtypes(include=["object", "category"]).columns # Numeric imputation if len(numeric_cols) > 0: if numeric_strategy == "knn": imputer = KNNImputer(n_neighbors=5) df[numeric_cols] = imputer.fit_transform(df[numeric_cols]) else: imputer = SimpleImputer(strategy=numeric_strategy) df[numeric_cols] = imputer.fit_transform(df[numeric_cols]) # Categorical imputation if len(categorical_cols) > 0: imputer = SimpleImputer(strategy="most_frequent") df[categorical_cols] = imputer.fit_transform(df[categorical_cols]) return df
pythondef detect_outliers_iqr(series, multiplier=1.5): """ Detect outliers using the IQR method. Standard multiplier is 1.5 (outlier) or 3.0 (extreme outlier). """ q1 = series.quantile(0.25) q3 = series.quantile(0.75) iqr = q3 - q1 lower = q1 - multiplier * iqr upper = q3 + multiplier * iqr outliers = (series < lower) | (series > upper) return outliers, lower, upper def detect_outliers_zscore(series, threshold=3.0): """ Detect outliers using z-score method. Threshold of 3.0 corresponds to 99.7% of normal distribution. Use modified z-score (MAD-based) for skewed distributions. """ from scipy import stats z_scores = np.abs(stats.zscore(series.dropna())) outliers = z_scores > threshold return outliers
Common domain validations:
Age: 0-120 (flag > 100)
Height (cm): 50-250
Weight (kg): 1-300
Blood pressure systolic: 60-250
Blood pressure diastolic: 30-150
Temperature (C): 30-45 for body temperature
Likert scale (1-5): only integer values 1-5
Percentage: 0-100
Latitude: -90 to 90
Longitude: -180 to 180
Year of birth: 1900-current_year
Email: matches standard regex patternpythonclass CleaningLog: """ Log all cleaning operations for reproducibility. Every step should be documented with before/after counts. """ def __init__(self): self.entries = [] self.version = 0 def log_step(self, step_name, description, rows_before, rows_after, cols_affected): self.version += 1 self.entries.append({ "version": self.version, "step": step_name, "description": description, "rows_before": rows_before, "rows_after": rows_after, "rows_removed": rows_before - rows_after, "columns_affected": cols_affected, }) def save_report(self, path): report_df = pd.DataFrame(self.entries) report_df.to_csv(path, index=False)
Reproducibility rules:
1. Never modify the raw data file -- always save cleaned versions
2. Use version numbers (data_v1_raw, data_v2_cleaned, data_v3_final)
3. Script every step -- no manual edits in Excel
4. Document every decision (why delete, why impute, why cap)
5. Include the cleaning script in supplementary materials
6. Record software versions (pandas, numpy, R packages)
7. Set random seeds for any stochastic imputation
8. Save intermediate datasets at major checkpointsA well-documented data cleaning pipeline not only improves the quality of research findings but also strengthens the credibility of the work during peer review. Reviewers increasingly expect transparent data handling practices, and journals like PLOS ONE and Nature require data availability statements that implicitly demand reproducible preprocessing.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-23 | fail→fail | 18,442 | 14,058 | -24% | 1 | 1 | 0% | 4,258 | 4,968 | +17% | 0 | 0 | — |
case-01 | fail→fail | 25,231 | 33,794 | +34% | 1 | 1 | 0% | 5,121 | 6,802 | +33% | 0 | 0 | — |
case-02 | fail→fail | 16,255 | 19,579 | +20% | 1 | 1 | 0% | 2,535 | 5,494 | +117% | 0 | 0 | — |
case-03 | fail→fail | 20,597 | 19,485 | -5% | 1 | 1 | 0% | 4,331 | 5,824 | +34% | 0 | 0 | — |
case-04 | pass→pass | 11,264 | 10,764 | -4% | 1 | 1 | 0% | 1,903 | 3,815 | +100% | 0 | 0 | — |
case-05 | pass→pass | 15,749 | 14,623 | -7% | 1 | 1 | 0% | 2,591 | 4,728 | +82% | 0 | 0 | — |
case-22 | pass→pass | 13,734 | 14,403 | +5% | 1 | 1 | 0% | 2,741 | 4,954 | +81% | 0 | 0 | — |
case-06 | pass→pass | 13,690 | 15,964 | +17% | 1 | 1 | 0% | 2,107 | 4,583 | +118% | 0 | 0 | — |
case-07 | fail→pass | 14,258 | 12,139 | -15% | 1 | 1 | 0% | 3,023 | 4,361 | +44% | 0 | 0 | — |
case-08 | fail→pass | 12,556 | 8,750 | -30% | 1 | 1 | 0% | 2,340 | 3,847 | +64% | 0 | 0 | — |
case-09 | fail→fail | 15,313 | 12,299 | -20% | 1 | 1 | 0% | 2,763 | 4,301 | +56% | 0 | 0 | — |
case-10 | fail→fail | 15,079 | 14,426 | -4% | 1 | 1 | 0% | 2,587 | 4,829 | +87% | 0 | 0 | — |
case-11 | fail→fail | 16,468 | 20,623 | +25% | 1 | 1 | 0% | 3,046 | 6,196 | +103% | 0 | 0 | — |
case-12 | fail→fail | 23,920 | 24,265 | +1% | 1 | 1 | 0% | 4,934 | 6,961 | +41% | 0 | 0 | — |
case-13 | fail→pass | 18,259 | 19,973 | +9% | 1 | 1 | 0% | 3,009 | 5,696 | +89% | 0 | 0 | — |
case-14 | fail→pass | 18,313 | 19,194 | +5% | 1 | 1 | 0% | 2,910 | 5,527 | +90% | 0 | 0 | — |
case-15 | pass→pass | 15,282 | 17,782 | +16% | 1 | 1 | 0% | 2,424 | 4,679 | +93% | 0 | 0 | — |
case-16 | pass→pass | 16,722 | 24,254 | +45% | 1 | 1 | 0% | 2,702 | 5,934 | +120% | 0 | 0 | — |
case-17 | fail→pass | 16,854 | 23,482 | +39% | 1 | 1 | 0% | 2,768 | 5,879 | +112% | 0 | 0 | — |
case-18 | pass→pass | 17,297 | 15,683 | -9% | 1 | 1 | 0% | 2,831 | 4,567 | +61% | 0 | 0 | — |
case-19 | pass→pass | 10,076 | 6,309 | -37% | 1 | 1 | 0% | 1,745 | 2,993 | +72% | 0 | 0 | — |
case-20 | pass→pass | 12,450 | 13,573 | +9% | 1 | 1 | 0% | 2,568 | 4,926 | +92% | 0 | 0 | — |
case-21 | pass→pass | 20,261 | 19,434 | -4% | 1 | 1 | 0% | 3,984 | 6,148 | +54% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +22 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.