一键导入
harmonize-names
Normalize names in a CSV column with user guidance. Use when asked to fix, harmonize, or edit a column of names or similar values.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Normalize names in a CSV column with user guidance. Use when asked to fix, harmonize, or edit a column of names or similar values.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | harmonize-names |
| description | Normalize names in a CSV column with user guidance. Use when asked to fix, harmonize, or edit a column of names or similar values. |
head -n 5 input.csv
If the CSV has headers, read the header row and a few data rows to identify the column that most likely contains the target names. If more than one column could apply, ask the user which one to work on. Ignore any obvious trailing notes or extra rows.
Record the column name and index.
Create a crosswalk CSV named <column name>_crosswalk.csv with two columns: raw and mapped. Store it in an intermediate/ folder next to the source CSV. If the file already exists, ask the user whether they want to continue. If so, you may continue and overwrite the file.
Use Python's csv library to extract the unique values from the target column.
import csv
target_column = "name" # Replace with the detected column name.
with open("input.csv", newline="", encoding="utf-8") as f:
reader = csv.DictReader(f)
unique_values = sorted({row[target_column] for row in reader if row.get(target_column)})
print(unique_values)
Review the extracted values for inconsistencies and misspellings.
USA, United States of America, and US of A might combine to USA.For both kinds of changes, append the raw and corrected values to the crosswalk.
Use Python's csv library to write and run a script that:
processed/ folder at the same level as the source CSVimport csv
from pathlib import Path
source_csv = Path("input.csv")
crosswalk_csv = Path("intermediate/name_crosswalk.csv")
output_csv = Path("processed/input_corrected.csv")
target_column = "name" # Replace with the detected column name.
with crosswalk_csv.open(newline="", encoding="utf-8") as f:
mapping = {row["raw"]: row["mapped"] for row in csv.DictReader(f)}
with source_csv.open(newline="", encoding="utf-8") as f:
rows = list(csv.DictReader(f))
fieldnames = rows[0].keys()
for row in rows:
value = row.get(target_column)
if value in mapping:
row[target_column] = mapping[value]
output_csv.parent.mkdir(parents=True, exist_ok=True)
with output_csv.open("w", newline="", encoding="utf-8") as f:
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(rows)