mercredi 17 septembre 2014

Read csv file, write "like-items" to separate csv files


Vote count:

0




I have a csv file structured as so:



name, sid, amount
john, 5, 12
john, 2, 13
peter, 1, 10
john, 5, 4
peter, 1, 4


What I want to do is read this file, and then write separate files with the appropriate row info for each unique name/sid combination.


In this instance I would have 3 unique files: One for john 5, one for peter 1, and one for john 2.


the john 1 file would only have the following info:



john, 5, 12
john, 5, 4


Have no idea how to do this effectively.


Here's what I have so far, just opening the file and reading it:



with open(my_file, 'rb') as csvfile:
# skip header file
next(csvfile)
filereader = csv.reader(csvfile, delimiter=',')
for row in filereader:
print row


asked 8 secs ago

kylex

3,838






Read csv file, write "like-items" to separate csv files

Aucun commentaire:

Enregistrer un commentaire