ACS Description (Directly from ACS API Website)
Specify ACS Variables that will be pulled:
1. Ingest ACS Data
In [83]:
# Import Dependencies #
import os
import requests
In [84]:
# Create Data Frames #
censusKey="683a4bd2b0db3ca927d4fe5dd14df9275be4cb7c"
varlist="NAME,B01003_001E,B19013_001E,B25064_001E,B07012_002E,B25088_002E,B01002_002E,B01002_003E"
year = ["2014"]
In [85]:
def api_download(year):
path_year = os.path.join(os.getcwd(),"ACS", year)
file_name = path_year + "/" + "ACS" + year + ".txt"
url="http://api.census.gov/data/"+year+"/acs5?get="+varlist+"&for=county:*&key="+censusKey
if not os.path.exists(path_year):
os.makedirs(path_year)
else:
census_data = requests.get(url)
f = open(file_name, "w")
f.write(census_data.text.encode('utf-8'))
f.close()
def main():
"""
Main execution
"""
for year in years:
api_download(year)
if __name__ == '__main__':
main()
In [86]:
import pandas as pd
import os
import csv
import xlrd
filepath = os.path.join(os.getcwd(),"ACS", "2014", "ACS2014.txt")
df= pd.read_csv(filepath)
In [87]:
list(df.columns.values)
Out[87]: