-
Notifications
You must be signed in to change notification settings - Fork 0
/
dvla_csv_reader.py
35 lines (27 loc) · 963 Bytes
/
dvla_csv_reader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# DVLA reader thingy
things_i_care_about = []
import csv
with open('DVLA_FOI_LSOA_v2.csv') as csvfile:
dvla_reader = csv.DictReader(csvfile)
for row in dvla_reader:
#print ( row.keys() )
# lan2020 -- location
# year -- year :/
# cars
# pop18plus -- over 18s
#lsoan -- Lower layer Super Output Area (LSOA)
# https://www.doogal.co.uk/LSOA.php?code=E01000003
#City of London 001A
if "poole" in row['lsoan'].lower() :
things_i_care_about.append( row )
print('*', end='')
else:
print('.',end='')
for thing in things_i_care_about:
print (thing['lsoan'], thing['year'], thing['cars'], thing['pop18plus'])
with open('poole.csv', 'w', newline='') as csvfile:
fieldnames = ['year', 'cars', 'pop18plus']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for thing in things_i_care_about:
writer.writerow({'year': thing['year'], 'cars': thing['cars'], 'pop18plus' : thing['pop18plus'] })