Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, Zeep response to pandas

I am tryng to conenct to a SOAP webservice and use pandas to put in on a table.

Zeep give me this list:

[{
    'ssPeca': '103',
    'ssQtd': '1',
    'ssUn': 'un'
}, {
    'ssPeca': '291A',
    'ssQtd': '8',
    'ssUn': 'un'
}, {
    'ssPeca': '406B',
    'ssQtd': '8',
    'ssUn': 'un'
}]

my code is this:

client = zeep.Client(wsdl=wsdl)
pecas=client.service.TabelaPecas("C-160","CR")

pd.DataFrame.from_dict(pecas)

and that code generate this:

      0     1    2
0  ssPeca ssQtd ssUn 
1  ssPeca ssQtd ssUn 
2  ssPeca ssQtd ssUn 

but i want this:

      0     1    2
0    103    1   un 
1    291A   8   un 
2    406B   8   un 

can anyone help? i am just a beginner in python.

like image 487
Joao barreira Avatar asked Jan 30 '18 18:01

Joao barreira


1 Answers

Zeep has a function to transform the response into python objects. Eg: Ordered Dict.

You should use:

from zeep.helpers import serialize_object

client = zeep.Client(wsdl=wsdl)
pecas=client.service.TabelaPecas("C-160","CR")

pecas = serialize_object(pecas)

pd.DataFrame(pecas)

source: http://docs.python-zeep.org/en/latest/helpers.ht

edit: Fixed typo, thanks voglster

like image 134
Henrique Velasco Avatar answered Oct 02 '22 14:10

Henrique Velasco