|
|
@@ -0,0 +1,44 @@
|
|
|
+#!/usr/bin/env python
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+"""
|
|
|
+去除 construction_plan_standards.csv 中 first_zh_code 列前的序号
|
|
|
+"""
|
|
|
+
|
|
|
+import csv
|
|
|
+import re
|
|
|
+from pathlib import Path
|
|
|
+
|
|
|
+# 文件路径
|
|
|
+CSV_PATH = Path(__file__).parent / "construction_plan_standards.csv"
|
|
|
+
|
|
|
+def remove_chinese_number_prefix(text):
|
|
|
+ """去除中文数字序号前缀,如 '一、'、'二、' 等"""
|
|
|
+ # 匹配中文数字+顿号的模式
|
|
|
+ pattern = r'^[一二三四五六七八九十]+、'
|
|
|
+ return re.sub(pattern, '', text)
|
|
|
+
|
|
|
+def main():
|
|
|
+ # 读取CSV文件
|
|
|
+ rows = []
|
|
|
+ with open(CSV_PATH, 'r', encoding='utf-8-sig') as f:
|
|
|
+ reader = csv.DictReader(f)
|
|
|
+ fieldnames = reader.fieldnames
|
|
|
+ print(f"列名: {fieldnames}")
|
|
|
+ for row in reader:
|
|
|
+ old_value = row.get('first_zh_code', '')
|
|
|
+ new_value = remove_chinese_number_prefix(old_value)
|
|
|
+ if old_value != new_value:
|
|
|
+ print(f"修改: '{old_value}' -> '{new_value}'")
|
|
|
+ row['first_zh_code'] = new_value
|
|
|
+ rows.append(row)
|
|
|
+
|
|
|
+ # 写回CSV文件(不带BOM)
|
|
|
+ with open(CSV_PATH, 'w', encoding='utf-8', newline='') as f:
|
|
|
+ writer = csv.DictWriter(f, fieldnames=fieldnames)
|
|
|
+ writer.writeheader()
|
|
|
+ writer.writerows(rows)
|
|
|
+
|
|
|
+ print(f"已处理 {len(rows)} 行数据,序号已去除。")
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ main()
|