]> projects.mako.cc - matplotlib-cdsw/blob - load_hp_data.py
Start implementing plotting from the Harry Potter wikipedia data-set.
[matplotlib-cdsw] / load_hp_data.py
1 """ load_hp_data.py 
2
3 A module for loading data from the Harry Potter wikipedia data set
4
5 """ 
6 import csv
7 from datetime import datetime
8
9 f = open('hp_wiki.tsv', 'r')
10 reader = csv.DictReader(f, delimiter='\t')
11
12 columns = {}
13 for fieldname in reader.fieldnames:
14         columns[fieldname] = []
15
16
17 rows = []
18 for row in reader:
19         # Convert timestamp from a string to a date:
20         row['timestamp'] = datetime.strptime(row['timestamp'], '%Y-%m-%d %H:%M:%S')
21         rows.append(row)
22         for fieldname, value in row.items():
23                 columns[fieldname].append(value)

Benjamin Mako Hill || Want to submit a patch?