1
I have a CSV file with more than 9000 lines. I need to get a list with only one data of each line.
An example is the following:
01/02/19,carlos,casa,rio
03/05/18,luis,carro,maceio
06/04/17,camila,celular,teresina
I need to get a list of names only:
lista = ['carlos','luis','camila']
the closest I’ve come to that code:
csvRows=[]
arq_contas = open ('C:.../lista_contas.csv')
leitura_contas = csv.reader(arq_contas,delimiter=',', lineterminator='\n')
for row in leitura_contas:
csvRows.append(row[1:2])
print(csvRows)
but I got the following result:
['carlos'], [], ['luis'], [], ['camila'], [],
I am a beginner in Python and programming with a whole. That’s why I need a light from you.
Tries to replace
row[1:2]
forrow[1]
– Woss
the result was only: ['carlos']
– gustafsom
Only the first is
['carlos']
, but at the end of the loop will be['carlos', 'luis', 'camila']
. See here.– Woss
when I run mine appears only ['carlos'] and then this error: csvRows.append(Row[1]) Indexerror: list index out of range
– gustafsom
So it’s likely that you’re running a different code than the question.
– Woss
found the error. On each line there is an n. (https://repl.it/repls/DarksalmonAliceblueNanocad)
– gustafsom