I need to take a csv file that looks like this:
Name,Price1,Price2,Date1,Date2 ABC,1000,7500,5/1,6/1 DEF,3000,500,5/1,7/1 GHI,5000,3500,6/1,8/1
and write it to another csv file so that it looks like this:
Name,May,June,July,August ABC,7500,1000, , DEF,500, ,3000 GHI, ,3500, ,5000
spaces should be empty because nothing happens and this is the code that I still have
import csv with open('test-data.csv','rb') as f: csv_file=csv.reader(f) data=[row for row in csv_file] with open('csv-out.csv', 'wb') as out: writer=csv.writer(out) writer.writerow(['Name','May','June','July','August']) for row in data: writer.writerow(row[0])
I am new to python and I'm not sure how to use the cvs module. I was thinking of creating an array and just matching the numbers with the months. Since price1 goes with date2, and price2 goes with date1. Did I just think about that? I searched and possibly used the date and time to associate the month number with the name of the month. Any help or guidance is appreciated! Thanks again!
Edit:
It would be difficult if I wanted to add some numbers from a column, for example
Name,May,June,July,August ABC,7500,1000, , DEF,500, ,3000 GHI, ,3500, ,5000 Total,8000,4500,3000,5000