2
Hello, I have the following code:
import csv
def carregar_acessos():
X = []
Y = []
arquivo = open('acesso_pagina.csv', 'rb')
leitor = csv.reader(arquivo)
next(leitor)
for home,como_funciona,contato,comprou in leitor:
dado = [int(home),int(como_funciona),int(contato)]
X.append(dado)
Y.append([int(comprou)])
He tries to pull information from a CSV file containing several ZEROS and UNS. And I have another file that shows this in the terminal:
from dados import carregar_acessos
X,Y = carregar_acessos()
print(X)
print(Y)
But when I run the code the following error appears:
Traceback (most recent call last):
File "classifica_acesso.py", line 3, in <module>
X,Y = carregar_acessos()
File "/Users/josecarlosferreira/Desktop/machine-learning/dados.py", line 10, in carregar_acessos
next(leitor)
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
Well, I saw some answers in Stackoverflow in English, but even trying the solutions there proposed the code did not work and kept keeping the same error.
The CSV is created in this way:
home,como_funciona,contato,comprou
1,1,0,0
1,1,0,0
1,1,0,0
1,1,0,0
1,1,0,0
1,0,1,1
1,1,0,0
1,0,1,1
1,1,0,0
1,0,1,1
And it goes on like this for another 200 lines. They each indicate a YES(1) and NO(0) information. Could someone help me?
How is the structure of your csv?
– Marlysson
I edited the topic to demonstrate!
– JKFher