如何迭代SOAP API属性和具有相同名称但不同值的键?

时间:2016-07-18 16:41:24

标签: python-2.7 pandas soap dataframe

我正在尝试从Exact Target SOAP API响应中创建数据框,但如果响应对于我需要创建数据框的两个不同值具有相同的名称,我不知道如何处理。

这是系统输出的确切SOAP响应:

(SentEvent){
   Client = 
      (ClientID){
         ID = 11111111
      }
   PartnerKey = None
   PartnerProperties[] = 
      (APIProperty){
         Name = "ListID"
         Value = "11111111"
      },
      (APIProperty){
         Name = "SubscriberID"
         Value = "11111111"
      },
   ObjectID = None
   SendID = 11111111
   SubscriberKey = "aaa@aaa"
   EventDate = 2016-03-22 12:17:53.000024
   EventType = "Sent"
   TriggeredSendDefinitionObjectID = "11111111"
   BatchID = 1
 }]

我的目标是将所有属性放入数据框,但无法弄清楚如何检查“APIProperty”的值并将它们放在DataFrame中,如此

     APIPropertyListID            APIPropertySubscriberID
0    11111111                      111111111111
1    11111111                      111111111111

这是我的代码到目前为止,作为一个例子,我只在dataframe中做了一个属性,并为“APIProperty”尝试了类似的方法:

import ET_Client
import pandas as pd



try:
    debug = False
    stubObj = ET_Client.ET_Client(False, debug)
    print '>>>SentEvents'
    getSentEvent = ET_Client.ET_SentEvent()
    getSentEvent.auth_stub = stubObj
    getResponse4 = getSentEvent.get()
    ResponseResultsSentEvent = getResponse4.results
    #print ResponseResultsSentEvent

    ClientIDSentEvents = []
    #PartnerPropertiesSubscriberID = []

    for SentEvent in ResponseResultsSentEvent:
        ClientIDSentEvents.append(str(SentEvent['Client']['ID']))

    df4 = pd.DataFrame({'ClientIDSentEvents':ClientIDSentEvents})
    print df4

提前谢谢!

1 个答案:

答案 0 :(得分:0)

添加此行并为clientIDsentEvents

创建上面的列表
PartnerPropertiesListID.append(str(SentEvent['PartnerProperties'][0]['Value']))