I have a csv file that looks like this:
original csv:
vehicle,status,count
car1,used,10
car2,free,20
car1,free,3
car3,used,30
car3,free,10
I am trying to group the 'vehicles per their status and then create a file like this: final output:
vehicle,free,used
car1,3,10
car2,20,0
car3,10,30
I am was looking at python collections module, which i think can be used for a task like this. But not sure how to proceed Any pointers will be much appreciated.
i have the following code so far:
import collections
import csv
out=[]
with open('file.csv', "rb") as f:
reader = csv.DictReader(f)
for row in reader:
veh = row["vehicle"]
out[veh] = out.get(veh, collections.defaultdict(int))