Last active
February 21, 2020 13:47
-
-
Save Sparrow0hawk/5662d4aee021e6dd7be76c409db4bb80 to your computer and use it in GitHub Desktop.
Simple python function to lookup ONS output area codes and return relevant LSOA, MSOA, LAD etc codes
This file contains hidden or 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
| # function for mapping between OA, LSOA, MSOA | |
| import sys | |
| import pandas as pd | |
| # moved data read out of function call | |
| lookup_table = pd.read_csv('data/OA_lookup_table.csv') | |
| def ONS_OA_lookup(code, level, lookup_tbl=lookup_table): | |
| """ | |
| Using http://geoportal1-ons.opendata.arcgis.com/datasets/fe6c55f0924b4734adf1cf7104a0173e_0.csv | |
| Output Area to LSOA to MSOA to Local Authority District (December 2017) Lookup with Area Classifications in Great Britain data | |
| Simple lookup and return mappings for passed code | |
| """ | |
| accepted_levels = ['OA','LSOA','MSOA','LAD','RGN','CTRY'] | |
| if level in accepted_levels: | |
| print('Mapping with ',str(level)) | |
| else: | |
| print('Level provided not found. Please use one of the following: ',accepted_levels) | |
| return | |
| search_col = level + "11CD" | |
| narrow_table = lookup_table[lookup_table[search_col] == code] | |
| return narrow_table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment