Python根据依赖和独立列表计算csv文件中出现的次数



我想将计数依赖关系写入CSV的最后一列,但是它只显示在CSV的第一列。我面临的另一个问题是,它应该显示每一行的依赖关系的发生,但它只显示一次。我的目标是显示我的数据列出现的依赖。它应该显示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
dependence=['customer','team','job']
countdependence = 0
with open('importantdata.csv', 'r',encoding='utf-8', newline='n') as read_obj:
# reading by row
for row in read_obj:
# for each word in the dependence array
for word_in_dependence in dependence:
# checks if the word in dependence is in the row
if word_in_dependence in row.lower():
countdependence += 1
print(countdependence)