Monday, 15 September 2014

Python printing certain columns from .csv -



Python printing certain columns from .csv -

hello , give thanks reading. trying create python script print out columns of .csv

data base of operations looks like.

song_name,file_name,artist_name,artist_id song1,filename1,artistname,artist001 song1,filename1,artistname,artist001 song1,filename1,artistname,artist001 song1,filename1,artistname,artist001

and trying create new csv has

song_name,artist_id song1,artist001 song1,artist001 song1,artist001 song1,artist001

i using code:

import csv open('convert.csv','rb') i: open('converted.csv','wb') o: r = csv.dictreader(i) w = csv.dictwriter(o,'song_name artist_id'.split(),extrasaction='ignore') w.writeheader() in r: w.writerow(a)

the result bank .csv titled converted. doing wrong?

with open('convert.csv','r') infile, open('converted.csv','w') outfile: author = csv.writer(outfile, delimiter=',') row in csv.reader(infile): writer.writerow([row[0], row[-1]])

python csv export-to-csv

No comments:

Post a Comment