Python activity error


#41

I have been having the same problem. I think it doesn’t like pandas. As I have tried to execute my script with my pandas code, and without out, it works executing the code without. Which is annoying as most of my code is written with pandas. Hopefully they build some sort of extension for it.

If you managed to sort it out please let me know. Thanks


#42

It has nothing to do with the pandas library. Either the pandas library is not installed on your 32-Bit instance of Python (unlikely) or you are referencing a path incorrectly.

You can’t use short paths in Python like ‘Data/somefile.csv’. You have to use the full path or pass the full path. You can’t use a working directory variable in your Python script because the wrong path will be used.

I got the following code to execute successfully:

import pandas as pd
df = pd.read_excel(r'C:\Users\******\PycharmProjects\sandbox\Data\*****.xlsx')
for row in df.iterrows():
  print(row)

Can you share your entire script or possibly the problematic section?


#43

ah ok, just made the changes you suggested to my script for both reading and writing files within pandas but still get the same error. Attached is my script, the commented out lines is what I had before.

import pandas as pd
import datetime
import os


def read_and_return_excel():
	
    week_num = 38
    poa_excel_name = 'POA W' + str(week_num) + '.xlsx'
    #df_poa = pd.read_excel(os.getcwd() + '\\python_code\\email_attachments\\' + poa_excel_name)
    #df_utwo = pd.read_excel(os.getcwd() + '\\python_code\\email_attachments\\U2000 Name and Site Name.xlsx')
    df_poa = pd.read_excel(r'C:\Users\xxx\Documents\UiPath\test\python_code\\email_attachments\\' + poa_excel_name)
	df_utwo = pd.read_excel(r'C:\Users\xxx\Documents\UiPath\test\python_code\\email_attachments\\U2000 Name and Site Name.xlsx')
    return df_poa, df_utwo

def check_utwo_in_codigo(dfs):
	
    df_poa, df_utwo = dfs
    df_all = df_utwo.merge(df_poa, on='CODIGO_SITE')
    df_filtered = df_all[
           [
               'CODIGO_SITE',
               'U2000 Name',
               'Site Name 2G', 
               'Site Name 3G', 
               'Site Name 4G'
            ]
    ].copy()
    
    return df_filtered


def sort_ne_list(ne_df_unsorted):
	
	df_ne = pd.DataFrame()
    for idx, row in ne_df_unsorted.iterrows():
        utwo_list = [row['U2000 Name']] * 3
        df_dict = {
                'NE Name': [
                        row['Site Name 2G'],
                        row['Site Name 3G'],
                        row['Site Name 4G']
                     ],
                'U2000' : utwo_list
            }

        
        df_ne = df_ne.append(pd.DataFrame(df_dict))
        
    df_eone = df_ne.loc[df_ne['U2000'] == 'ATAE1']
    df_etwo = df_ne.loc[df_ne['U2000'] == 'ATAE2']
    df_ethree = df_ne.loc[df_ne['U2000'] == 'ATAE3']
	
	#df_eone.to_csv('atae1.csv', index=False)
    #df_etwo.to_csv('atae2.csv', index=False)
    #df_ethree.to_csv('atae3.csv', index=False)
    
    df_eone.to_csv('C:\Users\xxx\Documents\UiPath\test\python_code\\atae1.csv', index=False)
    df_etwo.to_csv('C:\Users\xxx\Documents\UiPath\test\python_code\\atae2.csv', index=False)
    df_ethree.to_csv('C:\Users\xxx\Documents\UiPath\test\python_code\\atae3.csv', index=False)
    
excel_dfs = read_and_return_excel()
ne_df_unsorted = check_utwo_in_codigo(excel_dfs)
sort_ne_list(ne_df_unsorted)

#44

I also double checked pandas is installed in the correct virtual environment.


#45

Did you double check that this works on its own? You used ‘\’ and ‘\\’ in the path names with the r’’ literal string flag.

You have to either use ‘\’ WITHOUT “r” or ‘’ WITH “r” like so:
'C:\\Users\\xxx\\Documents\\UiPath\\test\\python_code\\email_attachments\\U2000 Name and Site Name.xlsx'

OR

r'C:\Users\xxx\Documents\UiPath\test\python_code\email_attachments\U2000 Name and Site Name.xlsx'

#46

Yes just checked now am using it without “r” so with \\ but it is still throwing the same error mentioned in this post.


#47

Now I just commented out all my code except;

import pandas as pd
print(pd.DateTime())

And still get the error


#48

I am beginning to think is this worth it! As originally I needed to finish it quickly so I just run a recording of my opening conda prompt and running the file. But as now refactoring it I thought it would be good to sort this out, as my initial problem was the 64bit so changed that, but now it seems to not like pandas :thinking:


#49

pandas doesn’t have a DateTime method as far as I know.


#50

I can’t decide for you if this is worth your time, but python is highly useful tool and can be easily incorporated with UiPath once you get around these kinks.

I’m attempting to run your code on my machine now if you can wait.

In the meantime, I would try removing all of your comments from the current script as ‘\’ may be causing errors.


#51

You are correct I meant to use to_datetime().

Thank you for the help it is very much appreciated. I will try removing all comments now and run again. Hopefully it works :crossed_fingers:


#52

ok I removed everything and only left;

import pandas as pd
import datetime
import os

Still throwing the same error.


#53

I just ran this same script and it worked fine for me.

Unfortunately, the best I can say is to re-re-check your environment, as I believe the correct Anaconda installation or Python interpreter is NOT being referenced.

Any chance you could share your .xaml file with this sequence? I’m out of ideas if you can’t even get “import” to work.


#54

Sorry will do later, not in front of my laptop now. Thanks again for the help.


#55

Sorry for the late reply, I forgot send it. Attached is the .xaml file. I am still really stumped on this one.py.xaml (6.6 KB)


#56

Because you are using miniconda, you need to make sure that all packages you are using are installed manually in the 32-Bit instance of the miniconda installation.

Additionally, if this is something that you installed recently, you need to make sure you are using Python 3.6 and not Python 3.7.

I just did a fresh install of miniconda to test my theory, and pandas was NOT installed automatically.

If you install pandas for the correct instance, your script should work.


#57

This is originally what I have done. I downloaded the 32-bit miniconda, created a virtual env with python 3.6 and installed pandas to the specific environment. But if you look at the attachment. It says my python is version is 3.6 within my virtual env, The conda info shows that it is 32 bit but it says it is python 3.7 not sure how this is possible?


#58

actually further inspection on the environment it is actually using python 3.6 and pandas is installed.


# Name                    Version                   Build  Channel
alabaster                 0.7.12                   py36_0
asn1crypto                0.24.0                   py36_0
astroid                   2.0.4                    py36_0
babel                     2.6.0                    py36_0
backcall                  0.1.0                    py36_0
blas                      1.0                         mkl
bleach                    3.0.2                    py36_0
ca-certificates           2018.03.07                    0
certifi                   2018.10.15               py36_0
cffi                      1.11.5           py36h74b6da3_1
chardet                   3.0.4                    py36_1
cloudpickle               0.6.1                    py36_0
colorama                  0.4.0                    py36_0
cryptography              2.3.1            py36h74b6da3_0
decorator                 4.3.0                    py36_0
docutils                  0.14             py36h4cf9f97_0
entrypoints               0.2.3                    py36_2
et_xmlfile                1.0.1            py36ha14dd7c_0
icc_rt                    2017.0.4             h97af966_0
icu                       58.2                 h3fcc66b_1
idna                      2.7                      py36_0
imagesize                 1.1.0                    py36_0
intel-openmp              2019.0                      118
ipykernel                 5.0.0            py36h39e3cac_0
ipython                   7.0.1            py36h39e3cac_0
ipython_genutils          0.2.0            py36h011d6f9_0
isort                     4.3.4                    py36_0
jdcal                     1.4                      py36_0
jedi                      0.13.1                   py36_0
jinja2                    2.10                     py36_0
jpeg                      9b                   he27b436_2
jsonschema                2.6.0            py36hc586ae5_0
jupyter_client            5.2.3                    py36_0
jupyter_core              4.4.0                    py36_0
keyring                   15.1.0                   py36_0
lazy-object-proxy         1.3.1            py36hfa6e2cd_2
libiconv                  1.15                 hc4a7105_7
libpng                    1.6.34               h79bbb47_0
libsodium                 1.0.16               h9d3ae62_0
libxml2                   2.9.8                hadb2253_1
libxslt                   1.1.32               hf6f1972_0
lxml                      4.2.5            py36hef2cd61_0
markupsafe                1.0              py36hfa6e2cd_1
mccabe                    0.6.1                    py36_1
mistune                   0.8.3            py36hfa6e2cd_1
mkl                       2019.0                      118
mkl_fft                   1.0.6            py36hdbbee80_0
mkl_random                1.0.1            py36h77b88f5_1
nbconvert                 5.3.1                    py36_0
nbformat                  4.4.0            py36hfe36a2e_0
numpy                     1.15.2           py36ha559c80_0
numpy-base                1.15.2           py36h8128ebf_0
numpydoc                  0.8.0                    py36_0
openpyxl                  2.5.8                    py36_0
openssl                   1.0.2p               hfa6e2cd_0
packaging                 18.0                     py36_0
pandas                    0.23.4           py36h830ac7b_0
pandoc                    2.2.3.2                       0
pandocfilters             1.4.2                    py36_1
parso                     0.3.1                    py36_0
pickleshare               0.7.5                    py36_0
pip                       10.0.1                   py36_0
prompt_toolkit            2.0.6                    py36_0
psutil                    5.4.7            py36hfa6e2cd_0
pycodestyle               2.4.0                    py36_0
pycparser                 2.19                     py36_0
pyflakes                  2.0.0                    py36_0
pygments                  2.2.0            py36h1a04f08_0
pylint                    2.1.1                    py36_0
pyopenssl                 18.0.0                   py36_0
pyparsing                 2.2.2                    py36_0
pyqt                      5.9.2            py36h6538335_0
pysocks                   1.6.8                    py36_0
python                    3.6.0                         0
python-dateutil           2.7.3                    py36_0
pytz                      2018.5                   py36_0
pywin32                   223              py36hfa6e2cd_1
pyzmq                     17.1.2           py36hfa6e2cd_0
qt                        5.9.6            vc14h1e9a669_2
qtawesome                 0.5.1                    py36_1
qtconsole                 4.4.1                    py36_0
qtpy                      1.5.1                    py36_0
requests                  2.19.1                   py36_0
rope                      0.11.0                   py36_0
setuptools                40.4.3                   py36_0
simplegeneric             0.8.1                    py36_2
sip                       4.19.8           py36h6538335_0
six                       1.11.0                   py36_1
snowballstemmer           1.2.1            py36h5e2b779_0
sphinx                    1.8.1                    py36_0
sphinxcontrib             1.0                      py36_1
sphinxcontrib-websupport  1.1.0                    py36_1
spyder-kernels            0.2.6                    py36_0
sqlite                    3.25.2               hfa6e2cd_0
testpath                  0.4.2                    py36_0
tornado                   5.1.1            py36hfa6e2cd_0
traitlets                 4.3.2            py36h0dbcc04_0
typed-ast                 1.1.0            py36hfa6e2cd_0
urllib3                   1.23                     py36_0
vc                        14                   h0510ff6_3
vs2015_runtime            14.15.26706          h3a45250_0
wcwidth                   0.1.7            py36hc8ec93f_0
webencodings              0.5.1                    py36_1
wheel                     0.32.0                   py36_0
win_inet_pton             1.0.1                    py36_1
wincertstore              0.2              py36hcdd9a18_0
wrapt                     1.10.11          py36hfa6e2cd_2
xlrd                      1.1.0                    py36_1
zeromq                    4.2.5                he025d50_1
zlib                      1.2.11               hbb18732_2

#59

guys, we have released a new version of the python package that now supports 64bit.
python 3.7 support will come in a future update.


#60

Thanks, will this be soon?