sinopec-safe-questions-analyse/判断.py
2025-08-12 20:47:01 +08:00

22 lines
788 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
# 读取 CSV去掉空白列
df = pd.read_csv(file_path, usecols=["题干(必填)", "正确答案\n(必填)"])
# 定义映射:判断题“正确”/“错误” -> A / B
ans_map = {"正确": "A", "错误": "B"}
# 构造结果列表
result = []
for _, row in df.iterrows():
q = str(row["题干(必填)"]).strip()
ans_text = str(row["正确答案\n(必填)"]).strip()
ans = ans_map.get(ans_text, ans_text) # 如果不是判断题格式,就原样保留
a = ["A.正确", "B.错误"]
result.append({"q": q, "a": a, "ans": ans})
# 保存为一行一个 JSON
output_path = "/mnt/data/questions.json"
with open(output_path, "w", encoding="utf-8") as f:
for item in result:
f.write(json.dumps(item, ensure_ascii=False) + "\n")