I'm having trouble copying a column of data into a csv file.
The original csv file looks something like this:
ID;texto
1;El niño juega
2;La rana salta
3;Mi código no funciona
The code I use reads data from a csv file, and generates a list. Then I try to paste that list into another CSV. I do the following:
import csv
with open("scraped.csv", "r", encoding="utf8") as csvfile:
reader = csv.DictReader(csvfile, dialect='unix', delimiter = ",")
sent =[]
for row in reader:
sent.append(row["texto"])
with open("results.csv", 'wb') as csvfile:
writer = csv.writer(csvfile, dialect='unix', delimiter=",",
quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(['texto'])
writer.writerow([sent])
I get the following error: Traceback (most recent call last): File "C: / Users / Testing 2.py", line 46, in writer.writerow (['text']) TypeError: a bytes-like object is required, not 'str'
The objective is to be able to copy each phrase in a row in the new csv file, under the text title.
Thanks for the suggestions