I have a csv file that looks like this:
Date Name Wage
5/1/19 Joe $100
5/1/19 Sam $120
5/1/19 Kate $30
5/2/19 Joe $120
5/2/19 Sam $134
5/2/19 Kate $56
5/3/19 Joe $89
5/3/19 Sam $90
5/3/19 Kate $231
I would like to restructure it to look like this:
Date Joe Sam Kate
5/1/19 $100 $120 $30
5/2/19 $120 $134 $56
5/3/19 $89 $90 $231
I am not sure how to approach it. Here is what I started writing:
import csv
with open ('myfile.csv', 'rb') as filein, open ('restructured.csv', 'wb') as fileout:
rows = list(csv.DictReader(filein, skipinitialspace=True))
names = NOT SURE HOW TO GET THIS
fieldnames = ['Date'] + ['{}'.format(i) for i in names]
csvout = csv.DictWriter(fileout, fieldnames=fieldnames, extrasaction='ignore', restval='NA')
csvout.writeheader()
for row in rows:
row['{}'.format(row['Name'].strip())] = row['Wage']
csvout.writerow(row)
list(csv.DictReader(filein, skipinitialspace=True))return what you expect?