CSV のクリーニングと重複チェック(変更ログつき)

CSV clean and dedupe with a change log

文字コードや区切り文字を自動判定し、全角半角・空白・日付・電話番号をそろえ、重複候補を洗い出します。元ファイルは変更せず、整えたコピーと変更ログを出力します。

ClaudeHermes AgentCodexCursorMIT(改変・再配布・商用利用可)Python

できること

顧客リストや古いシステムから書き出した CSV を、元ファイルに手を加えずに整えます。

  • 文字コード(UTF-8、BOM 付き UTF-8、Shift_JIS/CP932、EUC-JP)と区切り文字(カンマ・タブ・セミコロン・縦棒)を自動判定
  • 列ごとのプロファイル(空欄数、値の種類、全角英数字や半角カナを含むセル数、前後の空白、列数がずれた行)
  • 全角英数字→半角、半角カナ→全角、全角スペース→半角スペース、前後・連続スペースの整理(丸数字などはそのまま)
  • 日付を YYYY-MM-DD に統一(2024/1/5、20240105、「2024年1月5日」、R6.1.5 や「令和6年」などの和暦に対応)
  • 電話番号のハイフン・括弧・+81 の統一(数字だけ/ハイフン区切り/+81 形式から選択)
  • 重複の検出:完全一致、指定キー(メールアドレスや顧客 ID など)での一致、会社名などのあいまい一致(「株式会社」「(株)」の有無は無視)
  • 変更したセルをすべて changes.csv に記録(行・列・変更前・変更後・適用ルール)

使い方

python scripts/csv_clean.py profile input.csv
python scripts/csv_clean.py clean input.csv --out-dir cleaned/ --key "メール" --fuzzy-key "会社名"

エージェントがまずプロファイル結果を説明し、日付列・電話番号列・重複判定のキーをあなたと確認してから整形します。重複候補は自動では消さず、一覧を見ながら一緒に判断します。

必要な環境

  • Python 3(標準ライブラリのみ)

注意点

  • 入力ファイルは読むだけで、上書き・削除はしません。出力先に同名ファイルがあると止まります(--force で上書き)。
  • 出力は Excel で文字化けしない BOM 付き UTF-8 が既定です。Shift_JIS が必要なら --out-encoding cp932(変換できない文字があるとエラーになります)。
  • 「01/02/2024」のように月日の順番が読み取れない日付は、指定がない限り変更しません。
  • あいまい一致は候補の提示です。支店など別の相手が含まれることがあります。5,000 行を超える場合は上限を引き上げるかキー指定を使ってください。
English description

Detects encoding and delimiter, normalizes width, spaces, dates and phone numbers, and finds duplicate candidates. Writes a cleaned copy plus a change log; the input is never modified.

What it does

Cleans CSV exports (customer lists, data from legacy systems) without touching the original file.

  • Detects the encoding (UTF-8, UTF-8 with BOM, Shift_JIS/CP932, EUC-JP) and the delimiter (comma, tab, semicolon, pipe)
  • Profiles each column: empty cells, value kinds, cells with full-width ASCII or half-width katakana, edge spaces, ragged rows
  • Normalizes width (full-width ASCII to half-width, half-width katakana to full-width, ideographic space to a normal space) and trims spaces, while keeping symbols such as circled digits
  • Unifies dates to YYYY-MM-DD, including 2024/1/5, 20240105, Japanese year-month-day notation and Japanese era dates such as R6.1.5
  • Unifies phone number separators and +81 (choose digits only, hyphenated, or +81 format)
  • Finds duplicates: exact rows, an exact business key (email, customer ID), and fuzzy matches on names that ignore legal-entity suffixes
  • Logs every changed cell in changes.csv (row, column, before, after, rule)

How to use

python scripts/csv_clean.py profile input.csv
python scripts/csv_clean.py clean input.csv --out-dir cleaned/ --key "email" --fuzzy-key "company"

The agent explains the profile first, confirms the date and phone columns and duplicate keys with you, then cleans. Duplicate candidates are never removed silently; you review them together.

Requirements

  • Python 3 (standard library only)

Caveats

  • The input file is only read, never overwritten or deleted. Existing output files are not replaced without --force.
  • Output defaults to UTF-8 with BOM so Excel opens it correctly. Use --out-encoding cp932 for Shift_JIS; characters that Shift_JIS cannot hold cause an error.
  • Dates like 01/02/2024 whose day/month order is unknown are left unchanged unless you specify the order.
  • Fuzzy matches are candidates only and may include branch offices. Above 5,000 rows, raise the limit or use an exact key.

インストール方法

  1. ダウンロードしたZIPを展開します(中に csv-clean-and-dedupe/ フォルダと SKILL.md があります)。
  2. フォルダごと、使うエージェントのスキル置き場にコピーします。
    • Claude:~/.claude/skills/(プロジェクト単位なら .claude/skills/)
    • Hermes Agent:~/.hermes/skills/
    • Codex:~/.agents/skills//Cursor:~/.cursor/skills/
    • Claude アプリ(claude.ai):「カスタマイズ → スキル」からZIPをアップロード
  3. エージェントを再起動し、スキル一覧に表示されることを確認します。

Windows・Mac 別、エージェント別のインストール手順

出品者

AI Skill Market 公式

出品スキル 44 件

出品者のプロフィールとスキル一覧