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.

2 Likes

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!

3 Likes

Hi @Adit2917

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

Thanks for it

Nived N :robot:

1 Like