Commit 02226617 authored by 李盟's avatar 李盟

Upload New File

parent f9515dfa
Pipeline #505 canceled with stages
import os
import re
import json
import pandas as pd
file_list = os.listdir("/home/limeng/NLP/LLM/code/0220/result")
files_sorted = sorted(file_list, key=lambda x: int(re.search(r'(\d+)', x).group()))
json_folder_path = "/home/limeng/NLP/LLM/code/0220/result"
for filename in files_sorted:
# 读取 JSON 文件
file_path = os.path.join(json_folder_path, filename)
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
# 提取 extracted_info 字段
extracted_info = data.get("extracted_info", {})
# 创建一个字典用于存储这条数据
row_data = {}
# 遍历 extracted_info 中的键值对,填充到字典中
for key, value in extracted_info.items():
row_data[key] = value
for column in df.columns:
if column not in row_data:
row_data[column] = "无"
# 将 row_data 添加到 DataFrame 中
new_row = pd.DataFrame([row_data])
df = pd.concat([df, new_row], ignore_index=True)
# 输出结果 DataFrame
print(df)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment