Skip to main content
Cadet | Tier 2
November 8, 2023
Question

Does Pandas not work well with Python Script (Execute Function) Action?

  • November 8, 2023
  • 2 replies
  • 218 views

Greetings;
I’m trying to merge two xlsx files into one csv, using a Python Script, passing a “Month” Value (ex: ‘OCT23’)

Whenever I try to use pandas’ library, I ended up facing a ‘bot error’ in AA.
 

def func_sp(month):
import pandas as pd
nmonth = month

linka = r'PATHTOMYARCHIVE.xlsx'
cam = r'PATH'
arquivo = r'/expensescard_'
formato = ".xlsx"

link = cam + nmonth + arquivo + nmonth + formato
link_do_csv = cam + nmonth + '//'

###'TILL HERE, IT WORKS FINE####

abacartao = pd.read_excel(link, sheet_name=2)
abaclientes = pd.read_excel(link, sheet_name=1)

tel_sp = abaclientes[abaclientes['Número de Contato'].str.contains(r'/(11/)')]
tel_sp[['ID', 'Nome do Cliente', 'Número de Contato', 'Total de Dívidas Mês']]
cart_sp = abacartao[['ID_CLIENTE', 'Empresa Cartao', 'Saldo Final']]

resultado = tel_sp.merge(cart_sp, left_on='ID', right_on='ID_CLIENTE')
resultado.to_csv(link_do_csv + 'GastosClientesSP_' + nmes + '.csv')

return nmonth

 

In EXECUTE FUNCITON action:

Python Session Default
Enter name of funciton to be executed func_sp
Arguments to the function sMonth
Assign the output to variable sPythonFunctionOutput

 

Getting only ‘bot error’ message after running

2 replies

Aaron.Gleason
Automation Anywhere Team
Automation Anywhere Team
November 8, 2023

Be sure to put the import line at the TOP of your Python script, not within the function.

BoechatAuthor
Cadet | Tier 2
November 8, 2023

Solved;

Openpyxl installation was missing.