Last active
November 3, 2020 15:00
-
-
Save anil-kk/c5e007ba0df938121f5fa4e0da43ce16 to your computer and use it in GitHub Desktop.
Create lookup<region_code,name> for regions in Sweden from SCB data
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 pandas as pd | |
import requests | |
import json | |
session = requests.Session() | |
res = session.get("http://api.scb.se/OV0104/v1/doris/sv/ssd/START/BE/BE0101/BE0101A/BefolkningNy") | |
region_variables = json.loads(res.content.decode('utf-8-sig'))['variables'] | |
regions_lookup = {} | |
for variable in region_variables: | |
regions_lookup[variable['text']] = dict(zip(variable['values'], variable['valueTexts'])) | |
regions_lookup['region'] | |
regions_df=pd.DataFrame.from_dict({'code':list(regions_lookup['region'].keys()),'name':list(regions_lookup['region'].values())}) | |
regions_df.to_csv('region_lookup.csv',index=None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment