Python, Zeep response to pandas

2024/11/17 1:48:51

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.

Answer

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

You should use:

from zeep.helpers import serialize_objectclient = 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

https://en.xdnf.cn/q/71271.html

Related Q&A

Adjust the distance only between two subplots in matplotlib

I have 3 subplots (3 rows and 1 column). We can use fig.subplots_adjust(hspace=0.2) to adjust the distance between the subplots. this will change the distance between subplots for all case. How can I h…

Many-to-many multi-database join with Flask-SQLAlchemy

Im trying to make this many-to-many join work with Flask-SQLAlchemy and two MySQL databases, and its very close except its using the wrong database for the join table. Heres the basics... Ive got main_…

Merge two rows in the same Dataframe if their index is the same?

I have created a large Dataframe by pulling data from an Azure database. The construction of the dataframe wasnt simple as I had to do it in parts, using the concat function to add new columns to the d…

How do I use the Postgresql ANY operator in a NOT IN statement

Using Pyscopg2, how do I pass a Python list into an SQL statement using the ANY Operator?Normal Working SQL reads (See SQL Fiddle):SELECT * FROM student WHERE id NOT IN (3);Using Psycopg2 as below:Psy…

pass command-line arguments to runpy

I have two files, one which has a side effect I care about that occurs within the if __name__ == "__main__" guard:# a.py d = {} if __name__ == "__main__":d[arg] = helloThe second fi…

Altering my python path: helloworld.py returns command not found—

Massive apologies for this embarrassing question—Im using my MacBook Pro, running snow leopard, and using Python 2.7.1. Trying to run my first script and all the first pages of all my tutorials are la…

ImportError: cannot import name force_text

I have installed Python 2.7 and Django 1.4 in my CentOS machine and installed all dependencies for my existing project. When I run python manage.py runserver, I am getting the following traceback in my…

How can I select the pixels that fall within a contour in an image represented by a numpy array?

VI have a set of contour points drawn on an image which is stored as a 2D numpy array. The contours are represented by 2 numpy arrays of float values for x and y coordinates each. These coordinates are…

Get the value of specific JSON element in Python

Im new to Python and JSON, so Im sorry if I sound clueless. Im getting the following result from the Google Translate API and want to parse out the value of "translatedText":{"data"…

How does setuptools decide which files to keep for sdist/bdist?

Im working on a Python package that uses namespace_packages and find_packages() like so in setup.py:from setuptools import setup, find_packages setup(name="package",version="1.3.3.7"…