我想将计数相关性写入CSV的最后一列,但是,它只显示在CSV的第一列。我面临的另一个问题是,它应该显示每一行的相关性,但它只显示一次。 我的目标是在dependence列出现时显示我的数据。它应该显示0和1,而不是仅显示1
https://i.stack.imgur.com/NMNG2.png
writer = csv.writer(read_obj)
writer.writerow([countdependence])
在我添加了上面的代码之后,它给了我
https://i.stack.imgur.com/pA58a.png
dependence=['customer','team','job']
countdependence = 0
with open('importantdata.csv', 'r+',encoding='utf-8', newline='') as read_obj:
for i in read_obj:
for word in dependence:
if word in i.lower():
countdependence += 1
writer = csv.writer(read_obj)
writer.writerow([countdependence])
print(countdependence)
countdependence=0
相关问题 更多 >
编程相关推荐