简体   繁体   中英

Nested JSON file into Pandas Dataframe

I'm having trouble getting this nested JSON object into a pandas dataframe using python:

{
   "count":275,
   "calls":[
      {
         "connectedTo":"18885068980",
         "serviceName":"",
         "callGuid":"01541af0-d87c-4911-a868-f5ac573d1e31",
         "origin":"+19178558701",
         "stateChangedAt":"2016-04-15T18:21:23Z",
         "sequence":9,
         "appletName":"ACD Sales General"
      }
   ]
}

I've tried using json_normalize and am going in circles. Any help would be very much appreciated!

I know that it includes json_normalize, but I think this is what you are trying to do.

import json
import pandas as pd
from pandas.io.json import json_normalize
from pprint import pprint

j = json.dumps(  //to create the json
  {'count': 275, 
  "calls": 
  [{'connectedTo': "18885068980", 
        "serviceName":"", 
        "callGuid":"01541af0-d87c-4911-a868-f5ac573d1e31", 
        "stateChangedAt":"2016-04-15T18:21:23Z", 
        "sequence":9, 
        "appletName":"ACD Sales General"}]})

data = json.loads(j)
pprint(json_normalize(data['calls']))

which returns

      appletName                              callGuid  connectedTo  \
0  ACD Sales General  01541af0-d87c-4911-a868-f5ac573d1e31  18885068980   

   sequence serviceName        stateChangedAt  
0         9              2016-04-15T18:21:23Z 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM