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