import csv
import json
with open('A.csv','rt',encoding="utf-8") as csvfile:
reader = csv.DictReader(csvfile)
column = [row['symptom_list'] for row in reader] #["肢端缺血"]
# print(column)
f = open('y.csv', 'w', encoding="utf-8",newline='') #系统自动创建一个y.csv文件。并空格去掉
csv_file = csv.writer(f) #将内容写入y.csv文件
csv_file.writerow(['symptom_list']) #每一行分别写入symptom_list
s=set() #去重
for i_str in column: # column is a list of lists, i is a list of string
#print(i_str)
i_str=i_str.replace('\\',"/")
i_list=json.loads(i_str) #获取列表中的字符串,是一个json格式
for ii in i_list\
: # string inside list (we get list from json string)
print(ii)
s.add(ii)
for ii in s:
# csv_file.writerow(ii) #无,症,状,型,溃,疡
csv_file.writerow([ii]) #脓疱性痤疮
print(len(s))
f.close()
从列表中取出字符串并保存在csv中
最新推荐文章于 2024-06-26 15:30:44 发布