Last active
July 3, 2020 17:58
-
-
Save lancejohnson/daf4ea0c64aa089c9996f5640ff9bc4f to your computer and use it in GitHub Desktop.
Download a range of surnames by rank from Census.gov. It calls the Census.gov Surname API (you must have an API key from the government). Here is a link to the API https://www.census.gov/data/developers/data-sets/surnames.2010.html. I chose to call the top 100,000 surnames due to frequency. Page 4 of this explanatory PDF has an excellent frequen…
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
| import csv | |
| import os | |
| import requests | |
| CENSUS_API_KEY = os.environ.get("CENSUS_API_KEY", "") | |
| CENSUS_SURNAME_URL = "https://api.census.gov/data/2010/surname" | |
| params = { | |
| "key": CENSUS_API_KEY, | |
| "get": "NAME,COUNT", | |
| "RANK": "1:100000" | |
| } | |
| resp = requests.get(CENSUS_SURNAME_URL, params) | |
| last_names = resp.json() | |
| with open("lastnames.csv", "w") as outfile: | |
| writer = csv.writer(outfile) | |
| writer.writerows(last_names) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment