Spaces:
Sleeping
Sleeping
import pandas as pd | |
import csv | |
def save_csv_info(filepath, ID, output): | |
# 读取CSV文件 | |
# with open(f'./database_name.csv', 'r', encoding='utf-8') as file: | |
with open(filepath, 'r', encoding='utf-8') as file: | |
# 创建CSV读取器 | |
reader = csv.reader(file) | |
# 将内容存储到列表中 | |
rows = [] | |
for row in reader: | |
rows.append(row) | |
# 添加新行 | |
# new_row = ['New Data 1', 'New Data 2'] # 新行的数据 | |
new_row = [ID, output] # 新行的数据 | |
rows.append(new_row) | |
# 写入CSV文件 | |
# with open('./database_name.csv', 'w', newline='', encoding='utf-8') as file: | |
with open(filepath, 'w', newline='', encoding='utf-8') as file: | |
# 创建CSV写入器 | |
writer = csv.writer(file) | |
# 写入所有行 | |
writer.writerows(rows) | |
# close the file to save the data. | |
file.close() | |
# return None | |
# save_csv_info('./summary.csv', '123', 'text') |