Intention/ernie/1.py

17 lines
500 B
Python
Raw Normal View History

2025-03-16 14:40:56 +08:00
import pandas as pd
import json
# 读取 Excel 文件
excel_file = r"D:\bonus\Desktop\问题.xlsx"
df = pd.read_excel(excel_file)
# 只保留 text 和 prompt并转换格式
json_data = [{"text": row["问题"], "label": "知识问答"} for _, row in df.iterrows()]
# 保存为 JSON 文件
json_file = "知识问答.json"
with open(json_file, "w", encoding="utf-8") as f:
json.dump(json_data, f, ensure_ascii=False, indent=4)
print(f"Excel 数据已转换为 JSON 并保存到 {json_file}")