graphql json输出到 Dataframe

inkz8wg9  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(346)

我尝试了几种将json输出从graphql转换为pandas Dataframe 的方法,但没有成功。将其转换为 Dataframe 的最佳方式是什么?

{'data': {'posts': {'edges': [{'node': {'id': '303843',
      'name': 'hipCV',
      'tagline': 'Create an impressive resume in minutes',
      'votesCount': 71}},
    {'node': {'id': '303751',
      'name': 'Find Your First Frontend Job',
      'tagline': "Find your dream job, even if you've been rejected many times",
      'votesCount': 51}},
    {'node': {'id': '303665',
      'name': 'Epsilon3',
      'tagline': 'The OS for spacecraft and complex operations',
      'votesCount': 290}}]}}}
mefy6pfw

mefy6pfw1#

尝试:

df=pd.json_normalize(data['data']['posts']['edges'])

# here data is your json data

# If needed use:

df.columns=df.columns.str.split('.').str[1]

df的输出:

node.id  node.name                       node.tagline                                    node.votesCount
0   303843  hipCV                           Create an impressive resume in minutes              71
1   303751  Find Your First Frontend Job    Find your dream job, even if you've been rejec...   51
2   303665  Epsilon3                        The OS for spacecraft and complex operations        290

相关问题