1

关于如何将此 JSON 文件转换为可用数据帧格式的任何想法:

pd.read_json("http://api.census.gov/data/2014/acsse/variables.json")

以下是表格的外观:http ://api.census.gov/data/2014/acsse/variables.html

4

1 回答 1

3

说你从

df = pd.read_json("http://api.census.gov/data/2014/acsse/variables.json")

问题是该列是dicts:

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')
于 2016-08-09T08:33:13.367 回答