-2

I am using a suds to get data from a wsdl, and I have successfully gotten data from the corresponding service. Now in response, I have the below data which is the "sudsobject"

(rowset){item[] = ](row){]item[] = (column){name = "client_hi"value = "01.129"},(column){name = "vendor_hi"value = "01.199"(column){name = "src_bill_time"value = "1521.37"},},(row){item[] = (column){name = "client_hi"value = "01.129"},(column){name = "vendor_hi"value = None},(column){name = "src_bill_time"value = None},},(row){item[] = (column){name = "client_hi"value = "01.129"},(column){name = "vendor_hi"value = "01.196"},(column){name = "src_bill_time"value = "898.88"},}

Now, I need a Dataframe in pandas which are included of "name" as columns, included of 3 "row"s with data of "value" inside each cell.

Requested Output:

client_hi,vendor_hi,src_bill_time
1.129,1.199,1521.37
1.129,None,None
1.129,1.196,898.88

Also, I can convert it to json serialised format:

{'item': [{'name': 'client_hi', 'value': '01.129'}, {'name': 'vendor_hi', 'value': '01.199'}, {'name': 'src_bill_time', 'value': '1521.37'},]}

{'item': [{'name': 'client_hi', 'value': '01.129'}, {'name': 'vendor_hi', 'value': 'None'}, {'name': 'src_bill_time', 'value': 'None'},]} {'item': [{'name': 'client_hi', 'value': '01.129'}, {'name': 'vendor_hi', 'value': '1.196'}, {'name': 'src_bill_time', 'value': '898.88'},]}

But Still, I am looking for a way to create a data table to be imported inside the pandas included of "name" as columns, included of 3 "row"s with data of "value" inside each cell. (Like above "requested output")

  • It is hard to understand what do you receive back from your query, is it a json? csv? dict? pandas Data frame can usually read this types and make the appropriate data frame. – Green Apr 10 '20 at 17:13
  • It is a soap request "client.service.call()" for a wsdl method and in its response, I have gotten the XML response in code "client.service.selectRowset(), the final response give above (first), also the class is ". – Naeim Nadafchi Apr 10 '20 at 17:26

1 Answers1

0

I found the solution. I had to convert the suds object to JS serialized numbers:

def recursive_asdict(d):
"""Convert Suds object into serializable format."""
out = {}
for k, v in asdict(d).items():
    if hasattr(v, '__keylist__'):
        out[k] = recursive_asdict(v)
    elif isinstance(v, list):
        out[k] = []
        for item in v:
            if hasattr(item, '__keylist__'):
                out[k].append(recursive_asdict(item))
            elif not isinstance(item, list):
                out[k] = item
            else:
                out[k].append(item)
    else:
        out[k] = v
return out

and which gives the format mentioned in the question: {'item': [{'name'... Afterwards, with Regex, Convert to a python list with removing some characters and "value" and "name" which give me the below format:

[{'client_hi':  '01.129','vendor_hi':  '01.199' ,src_bill_time',  '1521.37',}]

and Finally using pandas

import pandas
df=pd.DataFrame(my_customized_list)