csv-data-wrangler

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CSV Data Wrangler

CSV数据处理

Purpose

用途

Provides expertise in efficient CSV file processing, data cleaning, and transformation. Handles large files, encoding issues, malformed data, and performance optimization for tabular data workflows.
提供高效CSV文件处理、数据清洗与转换的专业指导。可处理大型文件、编码问题、格式错误数据,并针对表格数据工作流进行性能优化。

When to Use

适用场景

  • Processing large CSV files efficiently
  • Cleaning and validating CSV data
  • Transforming and reshaping datasets
  • Handling encoding and delimiter issues
  • Merging or splitting CSV files
  • Converting between tabular formats
  • Querying CSV with SQL (DuckDB)
  • 高效处理大型CSV文件
  • 清洗与验证CSV数据
  • 转换与重塑数据集
  • 处理编码与分隔符问题
  • 合并或拆分CSV文件
  • 表格格式间转换
  • 使用SQL(DuckDB)查询CSV数据

Quick Start

快速入门

Invoke this skill when:
  • Processing large CSV files efficiently
  • Cleaning and validating CSV data
  • Transforming and reshaping datasets
  • Handling encoding and delimiter issues
  • Querying CSV with SQL
Do NOT invoke when:
  • Building Excel files with formatting (use xlsx-skill)
  • Statistical analysis of data (use data-analyst)
  • Building data pipelines (use data-engineer)
  • Database operations (use sql-pro)
调用此技能的场景:
  • 高效处理大型CSV文件
  • 清洗与验证CSV数据
  • 转换与重塑数据集
  • 处理编码与分隔符问题
  • 使用SQL查询CSV数据
请勿调用的场景:
  • 创建带格式的Excel文件(使用xlsx-skill)
  • 数据统计分析(使用data-analyst)
  • 构建数据管道(使用data-engineer)
  • 数据库操作(使用sql-pro)

Decision Framework

决策框架

Tool Selection by File Size:
├── < 100MB → pandas
├── 100MB - 1GB → pandas with chunking or polars
├── 1GB - 10GB → DuckDB or polars
├── > 10GB → DuckDB, Spark, or streaming
└── Quick exploration → csvkit or xsv CLI

Processing Type:
├── SQL-like queries → DuckDB
├── Complex transforms → pandas/polars
├── Simple filtering → csvkit/xsv
└── Streaming → Python csv module
按文件大小选择工具:
├── < 100MB → pandas
├── 100MB - 1GB → pandas(分块处理)或 polars
├── 1GB - 10GB → DuckDB 或 polars
├── > 10GB → DuckDB、Spark 或 流处理
└── 快速探索 → csvkit 或 xsv CLI

按处理类型选择:
├── 类SQL查询 → DuckDB
├── 复杂转换 → pandas/polars
├── 简单过滤 → csvkit/xsv
└── 流处理 → Python csv 模块

Core Workflows

核心工作流

1. Large CSV Processing

1. 大型CSV处理

  1. Profile file (size, encoding, delimiter)
  2. Choose appropriate tool for scale
  3. Process in chunks if memory-constrained
  4. Handle encoding issues (UTF-8, Latin-1)
  5. Validate data types per column
  6. Write output with proper quoting
  1. 分析文件(大小、编码、分隔符)
  2. 根据规模选择合适工具
  3. 内存受限时分块处理
  4. 处理编码问题(UTF-8、Latin-1)
  5. 验证各列数据类型
  6. 以正确的引用格式写入输出

2. Data Cleaning Pipeline

2. 数据清洗流程

  1. Load sample to understand structure
  2. Identify missing and malformed values
  3. Define cleaning rules per column
  4. Apply transformations
  5. Validate output quality
  6. Log cleaning statistics
  1. 加载样本以了解数据结构
  2. 识别缺失与格式错误的值
  3. 为各列定义清洗规则
  4. 应用转换操作
  5. 验证输出质量
  6. 记录清洗统计信息

3. CSV Query with DuckDB

3. 使用DuckDB查询CSV

  1. Point DuckDB at CSV file(s)
  2. Let DuckDB infer schema
  3. Write SQL queries directly
  4. Export results to new CSV
  5. Optionally persist as Parquet
  1. 将DuckDB指向CSV文件
  2. 让DuckDB自动推断模式
  3. 直接编写SQL查询
  4. 将结果导出为新CSV
  5. 可选:保存为Parquet格式

Best Practices

最佳实践

  • Always specify encoding explicitly
  • Use chunked reading for large files
  • Profile before choosing tools
  • Preserve original files, write to new
  • Validate row counts before/after
  • Handle quoted fields and escapes properly
  • 始终明确指定编码
  • 大型文件使用分块读取
  • 先分析再选择工具
  • 保留原始文件,写入新文件
  • 处理前后验证行数
  • 正确处理带引号的字段与转义字符

Anti-Patterns

反模式

Anti-PatternProblemCorrect Approach
Loading all to memoryOOM on large filesUse chunking or streaming
Guessing encodingCorrupted charactersDetect with chardet first
Ignoring quotingBroken field parsingUse proper CSV parser
No validationSilent data corruptionValidate row/column counts
Manual string splittingBreaks on edge casesUse csv module or pandas
反模式问题正确做法
全量加载至内存大型文件导致内存不足使用分块或流处理
猜测编码字符损坏先用chardet检测编码
忽略引号处理字段解析失败使用合适的CSV解析器
不进行验证数据静默损坏验证行/列数量
手动字符串拆分边缘场景下出错使用csv模块或pandas