Created
September 14, 2014 11:50
-
-
Save tom-henderson/35c601f29957934fa8c4 to your computer and use it in GitHub Desktop.
CSV to list of dicts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
# Assumes row 1 of the csv file contains the headers to use as keys | |
def get_csv_data(path): | |
data = [] | |
with open(path, 'rb') as f: | |
reader = csv.reader(f) | |
headers = reader.next() | |
for row in reader: | |
d = {} | |
for n, i in enumerate(row): | |
d[headers[n]] = i | |
data.append(d) | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment