Hi @Yudhisteer_Chintaram1 , Could you place the first two Import lines inside the function and test it.
Also assuming that the file assignment is not being used when used in UiPath. If used, please delete the file assignment line as well.
Let us know if this doesn’t work or if you get a different kind of error.
Could you Provide us the Code Snippet in a Text File or use the Ctrl + E to add the Code Snippet in the Preformatted text.
Also, we do see the file path assignment has been deleted, but the imports are not moved inside the function. Have we tested it by moving the imports inside the function?
import pandas as pd
import numpy as np
def func(file):
df = pd.read_excel(file)
print(df.head)
df.to_excel("output.xlsx",sheet_name='Country', index = False)
x = "Good"
return x
Yes. I tried with the imports inside the function and it still does not work.
On another note, have you tested to add the full path for the output file? I suspect that the script maybe is writing to a directory that you might not have write access to.
df.to_excel("c:/test/output.xlsx",sheet_name='Country', index = False)