Intention/ernie/1.py

17 lines
500 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 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}")