Created
August 3, 2020 12:32
-
-
Save raeq/efc09257887dedc2516454f90e0a3a04 to your computer and use it in GitHub Desktop.
Use the CSV package
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
from collections import defaultdict as dd | |
import requests | |
import csv | |
from pprint import pprint | |
url: str = "https://data.london.gov.uk/download/london-borough-profiles/c1693b82-68b1-44ee-beb2-3decf17dc1f8/london" "-borough-profiles.csv " | |
boroughs = (requests.get(url).text).split("\n") | |
reader = csv.DictReader(boroughs, dialect="excel") | |
dict1 = dd(dict) | |
for row in reader: | |
dict1[row["Code"]] = row | |
assert dict1["E09000001"]["Area_name"] == "City of London" | |
assert dict1["E09000032"]["Inner/_Outer_London"] == "Inner London" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment