Spaces:
Sleeping
Sleeping
Upload save_info.py
Browse files- save_info.py +35 -0
save_info.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import csv
|
3 |
+
|
4 |
+
def save_csv_info(filepath, ID, output):
|
5 |
+
# 读取CSV文件
|
6 |
+
# with open(f'./database_name.csv', 'r', encoding='utf-8') as file:
|
7 |
+
with open(filepath, 'r', encoding='utf-8') as file:
|
8 |
+
|
9 |
+
# 创建CSV读取器
|
10 |
+
reader = csv.reader(file)
|
11 |
+
|
12 |
+
# 将内容存储到列表中
|
13 |
+
rows = []
|
14 |
+
for row in reader:
|
15 |
+
rows.append(row)
|
16 |
+
|
17 |
+
# 添加新行
|
18 |
+
# new_row = ['New Data 1', 'New Data 2'] # 新行的数据
|
19 |
+
new_row = [ID, output] # 新行的数据
|
20 |
+
rows.append(new_row)
|
21 |
+
|
22 |
+
# 写入CSV文件
|
23 |
+
# with open('./database_name.csv', 'w', newline='', encoding='utf-8') as file:
|
24 |
+
with open(filepath, 'w', newline='', encoding='utf-8') as file:
|
25 |
+
# 创建CSV写入器
|
26 |
+
writer = csv.writer(file)
|
27 |
+
# 写入所有行
|
28 |
+
writer.writerows(rows)
|
29 |
+
|
30 |
+
# close the file to save the data.
|
31 |
+
file.close()
|
32 |
+
|
33 |
+
# return None
|
34 |
+
|
35 |
+
# save_csv_info('./summary.csv', '123', 'text')
|