You could use the csv
module anyway to read the CSV files into memory, then transpose the rows using zip(*rows)
or itertools.izip(*rows)
:
with open(somecsv, 'rb') as infile:
reader = csv.reader(infile, delimiter=';')
headers = next(reader)
data = list(reader)
data = dict(zip(headers, zip(*data)))
This creates a data
dictionary with the headers as keys and the columns as values. You can delete the ''
'terms' column from the dictionary if needed.
For your input example, the data
dictionary looks like this after executing the above code:
{'': ('term1', 'term2'), 'label1': ('1', '0'), 'label2': ('0', '0'), 'label3': ('8', '3')}