Hi Experts,
Greetings!
In my one use case, I am using this python code
"import tabula
from tabula import read_pdf
import pandas as pd
def read_pdf_and_sum(file_path, encoding=“utf-8”):
try:
# Specify the path to the PDF file
pdf_file_path = “Test.PDF”
# Read the PDF file
data = read_pdf(pdf_file_path, pages="all", encoding=encoding)
print("Data after reading PDF:", data)
# Combine the tables into a single DataFrame
merged_df = pd.concat(data, ignore_index=True)
print("Merged DataFrame:", merged_df)
# Identify columns with monetary values
monetary_columns = merged_df.columns[merged_df.apply(lambda col: col.str.contains('SAR')).any()]
# Convert identified columns to numeric
merged_df[monetary_columns] = merged_df[monetary_columns].replace({'[,SAR]': ''}, regex=True).apply(pd.to_numeric)
# Sum the identified columns and append the total values as the last row
total_values = merged_df[monetary_columns].sum().tolist() # Convert to list
merged_df = merged_df.append(dict(zip(monetary_columns, total_values)), ignore_index=True)
# Print all values in the total_values list
print("Total Values:")
for value in total_values:
print('{:,.2f}'.format(value))
# Print total_values in a specific format
print(','.join(map(str, total_values)))
return total_values
except Exception as e:
print(f"An error occurred: {e}")
return None
Call the function
total_values = read_pdf_and_sum(“Test.PDF”)
"
and it returns a list of integers, but when on my UiPath code I am using the “Get Python Object” activity, and it throws an error as “Get Python Object: Error converting Python object”. The output I am using is a list of integers.
Your help would be much appreciated.
Cheers