csv-data-wrangler
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCSV 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处理
- Profile file (size, encoding, delimiter)
- Choose appropriate tool for scale
- Process in chunks if memory-constrained
- Handle encoding issues (UTF-8, Latin-1)
- Validate data types per column
- Write output with proper quoting
- 分析文件(大小、编码、分隔符)
- 根据规模选择合适工具
- 内存受限时分块处理
- 处理编码问题(UTF-8、Latin-1)
- 验证各列数据类型
- 以正确的引用格式写入输出
2. Data Cleaning Pipeline
2. 数据清洗流程
- Load sample to understand structure
- Identify missing and malformed values
- Define cleaning rules per column
- Apply transformations
- Validate output quality
- Log cleaning statistics
- 加载样本以了解数据结构
- 识别缺失与格式错误的值
- 为各列定义清洗规则
- 应用转换操作
- 验证输出质量
- 记录清洗统计信息
3. CSV Query with DuckDB
3. 使用DuckDB查询CSV
- Point DuckDB at CSV file(s)
- Let DuckDB infer schema
- Write SQL queries directly
- Export results to new CSV
- Optionally persist as Parquet
- 将DuckDB指向CSV文件
- 让DuckDB自动推断模式
- 直接编写SQL查询
- 将结果导出为新CSV
- 可选:保存为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-Pattern | Problem | Correct Approach |
|---|---|---|
| Loading all to memory | OOM on large files | Use chunking or streaming |
| Guessing encoding | Corrupted characters | Detect with chardet first |
| Ignoring quoting | Broken field parsing | Use proper CSV parser |
| No validation | Silent data corruption | Validate row/column counts |
| Manual string splitting | Breaks on edge cases | Use csv module or pandas |
| 反模式 | 问题 | 正确做法 |
|---|---|---|
| 全量加载至内存 | 大型文件导致内存不足 | 使用分块或流处理 |
| 猜测编码 | 字符损坏 | 先用chardet检测编码 |
| 忽略引号处理 | 字段解析失败 | 使用合适的CSV解析器 |
| 不进行验证 | 数据静默损坏 | 验证行/列数量 |
| 手动字符串拆分 | 边缘场景下出错 | 使用csv模块或pandas |