My python script counts how many times a word list appears in a text. Script works but when I try to write results in a CSV file separated by semicolons but it doesn't work.
My code:
import csv
wordslist = ["Bob", "car"]
text = "Bob loves his Mustang car, but Bob wants a Ferrari car because Ferrari is a fastest car."
for word in wordslist :
resultCar = str(word) + "; " + str(text.count(word))
print resultCar
carCountsCsv = open("carcounts.csv", "wb")
with carCountsCsv:
writer = csv.writer(carCountsCsv)
writer.writerow(resultCar)
And my CSV file results is:
c,a,r,;, ,3
I don't understand why my result appear in the same row, I want to have this result like in the console:
Bob;2
car;3
Any help would be appreciated
c,a,r,;, ,3is my CSV file result