What's the best way to extract 2 values from a CSV file from each row systematically?
Luca Cerone
luca.cerone at gmail.com
Sat Sep 28 06:21:58 EDT 2013
> I'd really appreciate any suggestions or help, thanks in advance!
Hi Alex if you know that you want only columns 3 and 5, you could also use list comprehension to fetch the values:
import csv
with open('yourfile.csv','rU') as fo:
#the rU means read using Universal newlines
cr = csv.reader(fo)
values_list = [(r[2],r[4]) for r in cr] #you have a list of tuples containing the values you need
Cheers,
Luca
More information about the Python-list
mailing list