How to pass a Python DataFrame to UiPath?

I’m calling a python function using the UiPath Python Activities Pack (Get Python Object) and it returns a DataFrame in order to use it within UiPath. Unfortunately, UiPath is not able to convert the DataFrame to a .Net DataType like a DataTable.
Even when I try to convert the DataFrame to any other format (String, numpy array, html etc.) it is not working although the documentation mentions explicitly that all DataTypes are supported. The Python script does its work and stores the Content of the DataFrame in an Excel file and I could, of course, just read the Excel file. I was just wondering whether there is a way to directly pass the data to UiPath instead of saving it first and reading it again.


I am having this difficulty as well!

I was also having issues with this earlier, but found out this solution somewhere on stack overflow which worked for me.

You can convert the python dataframe to datatable format using the following three steps.

  1. Python Script:
    Return python data frame as JSON string i.e. return df.to_json(orient='records')
  2. Get Python Object:
    Save the JSON string in a variable of type string
  3. Deserialize JSON:
    Choose ‘System.Data.DataTable’ as TypeArgument and store the result in a variable of type dataTable

Tell me if this one works for you!


Hi @Adit2917

A brilliant answer. Json would be a good intermediate between Datatable and dataframe

Thanks for it

Nived N :robot:

1 Like

Great suggestion! This is pretty structure dependent. When I tried to deserialize my JSON it completely freaked out because of structure and header names. So I wrote the data to a temp Excel file from the Python file and ingested it into UiPath using Read Range and then reading the temp Excel file. Not the most optimised option, but it works.

Unfortunately, I am getting this error in invoke python method activity when I converted dataframe to json.

Error: Invoke Python Method: One or more errors occurred. (Error invoking Python method)

This is the script I am trying to execute. Please advice. (578 Bytes)

Hi @Adit2917 ,

Can you share a xaml which covers the steps which you mentioned.

It would be helpful.