有关如何将此JSON文件转换为可用的数据框格式的任何想法:
pd.read_json("http://api.census.gov/data/2014/acsse/variables.json")
表格的外观如下:http://api.census.gov/data/2014/acsse/variables.html
最佳答案
说你开始
df = pd.read_json("http://api.census.gov/data/2014/acsse/variables.json")
问题是该列是字典:
In [28]: df.variables.head()
Out[28]:
AIANHH {u'concept': u'Selectable Geographies', u'pred...
ANRC {u'concept': u'Selectable Geographies', u'pred...
BST {u'concept': u'Selectable Geographies', u'pred...
CBSA {u'concept': u'Selectable Geographies', u'pred...
CD {u'concept': u'Selectable Geographies', u'pred...
Name: variables, dtype: object
但是您可以通过应用
Series
解决此问题:In [27]: df.variables.apply(pd.Series)
Out[27]:
concept \
AIANHH Selectable Geographies
ANRC Selectable Geographies
BST Selectable Geographies
CBSA Selectable Geographies
CD Selectable Geographies
CNECTA Selectable Geographies
...
这可能是您想要的DataFrame,如下所示:
In [32]: df.variables.apply(pd.Series).columns
Out[32]: Index([u'concept', u'label', u'predicateOnly', u'predicateType'], dtype='object')