Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Converting from json to DataFrames?

I’m trying to convert json to DataFrames.

Json output from api is like that:

{
  "code": 0,
  "data": {
    "list": [
      {
        "address": "abcdxyz",
        "name": "Jack",
        "shares": "396",
        "amount": "490",
        "active": true
      },
      {
        "adress": "efghklm",
        "name": "Mary",
        "shares": "789",
        "amount": "890",
        "active": true
      }
    ],
    "page": 1,
    "size": 5,
    "maxPage": 1,
    "totalSize": 2
  }
}

When try

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

response = requests.get(url)
json_data = json.loads(response.text)
df = pd.DataFrame(json_data['data'])

its output like that

                    list  page  size  maxPage  totalSize
0  {'address': 'abcd...    1     5        1          2
1  {'address': 'efgh...    1     5        1          2

How can I reach output like that?:

      address    name  shares  amount active
0     abcdxyz    Jack    396    490    true
1     efghklm    Mary    789    890    true

I’ve tried several things but I couldn’t manage to print right way from list.
Thanks in advance

>Solution :

You had to go just one level deeper to access not the overall "data" but the specific "list":

response = requests.get(url)
json_data = json.loads(response.text)
df = pd.DataFrame(json_data['data']['list'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading