Created
June 17, 2018 07:46
-
-
Save TimSC/5495a14ac073fc8ef8fc362fd8d6db79 to your computer and use it in GitHub Desktop.
Filter National Statistics Office Postcode data set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
# Filtering file https://data.gov.uk/dataset/7ec10db7-c8f4-4a40-8d82-8921935b4865/national-statistics-postcode-lookup-uk | |
if __name__=="__main__": | |
reader = csv.DictReader(open("/home/tim/Downloads/National_Statistics_Postcode_Lookup_UK.csv")) | |
out = csv.DictWriter(open("natstats-po-postcodes.csv", "wt"), reader.fieldnames) | |
out.writeheader() | |
count = 0; | |
for li in reader: | |
#if li["Postcode 2"][:2] != "PO": | |
# continue | |
if li["Parliamentary Constituency Name"] not in ["Portsmouth North", "Portsmouth South"]: | |
continue | |
out.writerow(li) | |
count += 1 | |
if (count % 100) == 0: | |
print count | |
del out | |
del reader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment