我正在尝试将此美国人口普查局 api 数据获取请求放入数据框中,并认为它是一个列表列表,但显示为 NoneType。有没有办法将其制作成可以轻松导出到 CSV 文件的数据框?
import request
# The Basic API Request:
# Build base URL
HOST = "https://api.census.gov/data"
year = "2010"
dataset = "dec/sf1"
base_url = "/".join([HOST, year, dataset])
# Specify Census variables and other predicates
get_vars = ["NAME","P013001","P037001"]
predicates = {}
predicates["get"] = ",".join(get_vars)
predicates["for"] = "state:*"
# Execute the request, examine text of response object
data = requests.get(base_url, params=predicates)
print(data.text)
这确实会产生以下输出:
[["NAME","P013001","P037001","state"],
["Alabama","37.9","3.02","01"],
["Alaska","33.8","3.21","02"],
["Arizona","35.9","3.19","04"],
...
["Wyoming","36.8","2.96","56"],
["Puerto Rico","36.9","3.17","72"]]
胡说叔叔
相关分类