from itertools import groupby
r = csv.reader(open('fan.csv', 'rb'))
a = [([k] + [x[1] for x in g]) for k, g in groupby(r, key=lambda row: row[0])]
How to use python to transpose and remove duplicate value in table?