]> projects.mako.cc - matplotlib-cdsw/blob - wikibios.py
Add titles to the heatmaps
[matplotlib-cdsw] / wikibios.py
1 """
2 Module for loading data from wikipedia_bios.csv.
3 """
4
5 import csv
6 from datetime import datetime
7
8 f = open('wikipedia_bios.csv', 'r')
9 reader = csv.DictReader(f, quoting=csv.QUOTE_NONNUMERIC)
10 columns = {}
11 columns_female = {}
12 columns_male = {}
13 for fieldname in reader.fieldnames:
14         columns[fieldname] = []
15         columns_female[fieldname] = []
16         columns_male[fieldname] = []
17
18 rows = []
19 rows_female = []
20 rows_male = []
21
22 for row in reader:
23         # Convert firstedit from a string to a date.
24         row['firstedit'] = datetime.strptime(row['firstedit'], '%Y-%m-%d %H:%M:%S')
25         rows.append(row)
26         if row['gender'] == 'female':
27                 rows_female.append(row)
28         else:
29                 rows_male.append(row)
30         for fieldname, value in row.items():
31                 columns[fieldname].append(value)
32                 if row['gender'] == 'female':
33                         columns_female[fieldname].append(value)
34                 else:
35                         columns_male[fieldname].append(value)
36

Benjamin Mako Hill || Want to submit a patch?