Skip to content

Instantly share code, notes, and snippets.

@rob-smallshire
Created December 7, 2013 03:29
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 rob-smallshire/7836933 to your computer and use it in GitHub Desktop.
Save rob-smallshire/7836933 to your computer and use it in GitHub Desktop.
Read a CSV file into a dictionary of lists, using the column names in the first row as dictionary keys mapping to lists of numeric column data taken from subsequent rows in the CSV file.
import csv
with open('faithful.dat', newline='') as csvfile:
reader = csv.reader(csvfile, quoting=csv.QUOTE_NONNUMERIC)
names = next(reader)
columns = zip(*reader)
data = {name: column for name, column in zip(names, columns)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment