Created
August 3, 2020 12:34
-
-
Save raeq/322cd7e3a2b447c4b5668d4af7bca69f to your computer and use it in GitHub Desktop.
Use the CSV module
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 csv | |
import requests | |
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