Skip to content

Instantly share code, notes, and snippets.

@TimSC
Created June 17, 2018 07:46
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 TimSC/5495a14ac073fc8ef8fc362fd8d6db79 to your computer and use it in GitHub Desktop.
Save TimSC/5495a14ac073fc8ef8fc362fd8d6db79 to your computer and use it in GitHub Desktop.
Filter National Statistics Office Postcode data set
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