Caught Exception: Expected String or Buffer parsing JSON objects for use in DataFrame Pandas

时间:2016-07-11 19:41:54

标签: json pandas dataframe

I am trying to clean up some data from a SalesForce Exact Target API call, which is returned in JSON format.

The data looks like this coming with a combination of strings and integers. Below strings are going to be represented by "aaa" and numbers by "1111"

    }, (ClickEvent){
        Client = 
           (ClientID){
              ID = 111111111
           }
        PartnerKey = None
        CreatedDate = 1111-11-11 11:11:11
        ModifiedDate = 1111-11-11 11:11:11
        ID = 111111111
        ObjectID = "11111111"
        SendID = 1111111
        SubscriberKey = "aaaaaaaa@aaa.aaa"
        EventDate = 1111-11-11 11:11:11
        EventType = "Click"
        TriggeredSendDefinitionObjectID = None
        BatchID = 1
        URLID = 11111111
        URL = "http://aaaa.com
  }]

I am trying to iterate through the JSON objects and create Pandas DataFrame out of the objects like so:

  ParnterKey  CreatedDate
0 11111        111111
1  1111        1111

As a test in my code, I have setup a small piece of code to grab the data from "PartnerKey" and place it in a dataframe, but not sure what the error "expected string or buffer" means could anyone help me with this?

Code:

 import ET_Client
    import pandas as pd
    import json



    try:
        debug = False
        stubObj = ET_Client.ET_Client(False, debug)

        ## Modify the date below to reduce the number of results returned from the request
        ## Setting this too far in the past could result in a very large response size
        retrieveDate = '2016-07-08T13:00:00.000'

        #ET call for clicks
        print '>>>ClickEvents'
        getClickEvent = ET_Client.ET_ClickEvent()
        getClickEvent.auth_stub = stubObj   

        getResponse = getClickEvent.get()
        ResponseResults = [getResponse.results]

        result_json = json.loads(ResponseResults)
        jsonData = result_json["ClickEvent"]

        for item in jsonData:
            PartnerKey = item.get("PartnerKey")


        df = pd.DataFrame(JsonData)
        print df

except Exception as e:
    print 'Caught exception: ' + e.message
    print e

Thank you in advance!

0 个答案:

没有答案