Python 如何将JSON转换为数据帧
关于如何将此JSON文件转换为可用数据帧格式的任何想法:Python 如何将JSON转换为数据帧,python,json,pandas,census,Python,Json,Pandas,Census,关于如何将此JSON文件转换为可用数据帧格式的任何想法: pd.read_json("http://api.census.gov/data/2014/acsse/variables.json") 下面是表格的外观:假设您从 df = pd.read_json("http://api.census.gov/data/2014/acsse/variables.json") 问题在于,该列包含以下内容: In [28]: df.variables.head() Out[28]: AIANHH
pd.read_json("http://api.census.gov/data/2014/acsse/variables.json")
下面是表格的外观:假设您从
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
但您可以通过应用系列解决此问题:
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
...
这可能是您想要的数据帧,如下所示:
In [32]: df.variables.apply(pd.Series).columns
Out[32]: Index([u'concept', u'label', u'predicateOnly', u'predicateType'], dtype='object')
这不管用?