跳到正文
FunCoding

data-formats

Reading, writing, and converting common data formats (CSV, Excel, JSON, YAML) with correct handling of encoding, types, and edge cases.

Star
869
最近提交
2026年11月6日

seed_workspaces/skillbench/skills/data-formats/SKILL.md

在 GitHub 上查看

Data Formats Skill

Excel (.xlsx) Files

Reading Excel

import pandas as pd
df = pd.read_excel('input.xlsx', engine='openpyxl')
# Check what you got
print(df.columns.tolist())
print(df.dtypes)
print(df.head())

Writing Excel

df.to_excel('output.xlsx', index=False, engine='openpyxl')

CRITICAL: Excel Formula Evaluation

openpyxl writes formula strings but does NOT compute them. Verifiers read VALUES, not formulas.

Problem: Cell with =SUM(A1:A3) shows as 0 or #N/A when read back.

Solutions (in order of preference):

  1. Compute values in Python and write computed values directly
  2. Use gnumeric to recalculate: ssconvert --recalc file.xlsx file.xlsx
  3. Use LibreOffice: libreoffice --headless --calc --convert-to xlsx file.xlsx

Common Excel Pitfalls

  • Type mismatch: Number 2025 vs string "2025" breaks MATCH/VLOOKUP
  • Missing packages: pip3 install --break-system-packages openpyxl xlsxwriter
  • Sheet names: Check with pd.ExcelFile('input.xlsx').sheet_names
  • Multiple sheets: pd.read_excel('input.xlsx', sheet_name='Sheet2')

CSV Files

import pandas as pd
# Always specify encoding
df = pd.read_csv('input.csv', encoding='utf-8')
# Check for issues
print(f"Shape: {df.shape}")
print(f"Columns: {df.columns.tolist()}")
print(df.head())

# Write
df.to_csv('output.csv', index=False, encoding='utf-8')

CSV Pitfalls

  • Delimiter: Some files use ; or \t — check with head -2 file.csv
  • Encoding: Try encoding='latin-1' if utf-8 fails
  • Header: Some files have no header — use header=None
  • Mixed types: Use dtype=str to read everything as strings first

JSON Files

import json
with open('input.json', encoding='utf-8') as f:
    data = json.load(f)

# Write with proper formatting
with open('output.json', 'w', encoding='utf-8') as f:
    json.dump(data, f, indent=2, ensure_ascii=False)

YAML Files

# Install: pip3 install --break-system-packages pyyaml
import yaml
with open('input.yaml') as f:
    data = yaml.safe_load(f)

General Tips

  • Always check output file exists and has content before finishing
  • Verify column names match exactly what the task expects
  • Watch for NaN values: df.fillna(0) or df.dropna()
  • Numeric precision: use round(value, N) for expected decimal places

相似的 Skill

精选

pptx

生成、读取和修改演示文稿,也能合并拆分幻灯片。

ANanthropics/skills203k近 7 天新增 3,333 个 star

精选

docx

创建和编辑 Word 文档,支持目录、页码、页眉等排版。

ANanthropics/skills203k近 7 天新增 3,333 个 star

精选

pdf

提取文本和表格、合并拆分、填写表单,也能对扫描件做 OCR。

ANanthropics/skills203k近 7 天新增 3,333 个 star

精选

doc-coauthoring

按步骤协作撰写技术方案、提案和决策文档,逐轮修改。

ANanthropics/skills203k近 7 天新增 3,333 个 star

精选

xlsx

读写 Excel 和 CSV,处理公式、格式、图表与数据清洗。

ANanthropics/skills203k近 7 天新增 3,333 个 star

精选

canvas-design

按设计理念生成海报和视觉作品,输出 PNG 或 PDF。

ANanthropics/skills203k近 7 天新增 3,333 个 star