JSON文件作为每一行的字典输出,需要从i

2024-10-02 08:23:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个.json文件,当我通过-

df = pd.read_json('tummy.json')

输出看起来像-

     results
0   {u'objectId': u'06Dig7sXhU', u'SpecialProperti...'
1   {u'objectId': u'07VO1j4gVC', u'SpecialProperti...'

每一行似乎都是一本字典。我想提取每一行并从中创建一个数据帧。我真的很感激你对我的帮助


Tags: 文件数据jsondfread字典resultspd
1条回答
网友
1楼 · 发布于 2024-10-02 08:23:09

IIUC您可以使用:

import pandas as pd

s = pd.Series(( {u'objectId': u'06Dig7sXhU', u'SpecialProperties': u'456456'}, 
               {u'objectId': u'07VO1j4gVC', u'SpecialProperties': u'878421'}))
df = pd.DataFrame({'results':s})
print df
                                             results
0  {u'objectId': u'06Dig7sXhU', u'SpecialProperti...
1  {u'objectId': u'07VO1j4gVC', u'SpecialProperti...

print pd.DataFrame([x for x in df['results']], index=df.index)
  SpecialProperties    objectId
0            456456  06Dig7sXhU
1            878421  07VO1j4gVC

相关问题 更多 >

    热门问题