Skip to content

Instantly share code, notes, and snippets.

@tom-henderson
Created September 14, 2014 11:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tom-henderson/35c601f29957934fa8c4 to your computer and use it in GitHub Desktop.
Save tom-henderson/35c601f29957934fa8c4 to your computer and use it in GitHub Desktop.
CSV to list of dicts
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