Passing data from a csv to a list

0

I have a csv similar to the following:

ID;texto
1;Los niños comen sardinas
2;Los pájaros vuelan alto porque tienen alas
3;Érase una vez la vida
4;Un 67% de los adultos vive en la pobreza

I want to read the csv and extract the text column. I would like the text comments to be included in a list. I tried this:

import csv
import codecs
with codecs.open("Libro1.csv", "r") as csvfile:
    reader = csv.DictReader(csvfile, dialect='unix', delimiter = ";")
    list =[]
    for row in reader:
        list.append(row["c"])
        print (list)
    
asked by pyring 04.11.2017 в 14:27
source

1 answer

0

Agree. I understand that the idea I had was correct, the problem came because the print command had it inside the loop. So yes I get the list correctly:

import csv
import codecs
with codecs.open("Libro1.csv", "r") as csvfile:
    reader = csv.DictReader(csvfile, dialect='unix', delimiter = ";")
    list =[]
    for row in reader:
        list.append(row["c"])
print (list)
    
answered by 04.11.2017 в 14:41