Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Python tool

aberthiaume
7 - Meteor

I am trying to assist one of our data scientists with Alteryx.  He currently writes everything in Python, but due to a few things we take that data result and push it to Tableau using Alteryx.  The problem is he is currently having to monitor this constantly because the python code breaks.  My other colleague and I do not sue Python.  We thought if we could put the code in Alteryx we could assist when he is off or out of the office if a problem arises, if we simplify the process using alteryx.  With all that being said.  I have no experience with Python so I am tring to figure out how we pull in the Excel document he is starting with and attach his Python code using the python tool.  So far the videos I have seen show how to build the code using the python tool.  If it is already an existing code can we use the python tool to run what we already have?  If that explanation doesn't make sense, let me know and I will try to get a clearer explanation.  But basically we want to take an Excel file he gets from our Department of Health and Human Services  (so this would be the input tool) and run the python code that he currentlyalready has written (python tool) and then publish that to Tableau.  Thank you for any information you can offer. 

 

8 REPLIES 8
EWarmestad
6 - Meteoroid

Hi 

 

I don't know much python code, but I have been using it in one of my workflow. It might be possible to use the code. The python module in Alteryx read and configure it as a data frame type. 

 

if his code does the same it will be quite easy getting the code into a workflow, but having multiple python codes in a workflow might be a bit wobbly. I recommended making macro function and connecting it all together. 

 

Hope this give you a idea how to use python in Alteryx, there are also some great article in the community to get you started. 

Robin_McIntosh
11 - Bolide

@aberthiaume - I agree with with what @EWarmestad says about multiple python tools in a workflow.  If there are multiple, break them out into individual macros and call the macros as needed in the workflow.  I do this and have no issues.  Another benefit, is that if the same python code can be used over multiple workflows, you only have to maintain the one macro with the code and not all of the individual workflows.  =)

 

As far as your colleague goes, is his python code manipulating the Excel file?  If yes, is he using Openpyxl in the python code to do this?  How exactly is the python code working with the Excel file?  Can any of what's being done be converted to Alteryx tools instead or have you tried?

aberthiaume
7 - Meteor

Thank you for your response.  Here is some information I received from my colleague.  

 

Here’s an overview of the dependencies:

  • Selenium (web scraping)
    • This requires a bit of maintenance as we need to update the chromedriver as the machine’s version of Chrome auto-updates
    • It will open a separate browser tab to do the web automation
  • Xlwings (Excel automation):
    • Openpyxl is a lower dependency as well
    • Get the sheets and extract the data through them using pandas
  • Pandas (data manipulation):
    • Could hypothetically be replaced with Alteryx operations

 

The biggest things I see as issues that can’t be replicated in Alteryx are the Selenium and Xlwings portions (unless there is some good way to iterate through sheets in Excel).

haphan_tran
7 - Meteor

You Can use python tool to run the whole code that your data scientist build in Alteryx. But if you want a better performance, you can mix between Alteryx native tool (to read Excel, etc.) and python code. This will require you to understand python to break his code to smaller part.
Selenium: You can build the code to download the driver at runtime, so you don't have to manage it manually.
XLwings: this should be done via Alteryx for better performance and less dependencies.
Pandas: You can reuse his code, no need to rebuild it in Alteryx.

leofrancia
Alteryx
Alteryx

Hi @aberthiaume,

 

Just to add to the comments from @haphan_tran:

1. Consider the "Download" tool to get the data from Department of Health and Human Services. Check this out: https://www.thedataschool.co.uk/manuela-marolla/web-scraping-101-a-guided-example-in-alteryx-part-1

2.  Make sure to run Alteryx as Admin and install the dependencies using Alteryx syntax.

 

from ayx import Alteryx
Alteryx.installPackage(package=["openpyxl","fuzzysearch"])

 

3.  Do not forget to route the output of your data frames to the anchors as below and use the numbered anchor to connect to your next tile.

 

Alteryx.write(df, 1)

 

 

Regards.

Leo

haphan_tran
7 - Meteor

Thank you @leofrancia !
I worked in a big corporation and it is very hard to get admin right to run. So I figure I can install package under my user profile without Admin Right.

 

from ayx import Alteryx
Alteryx.installPackage(package=["openpyxl","fuzzysearch"],install_type="install --user")

 

leofrancia
Alteryx
Alteryx

Thanks, @haphan_tran! Will try this workaround the next time I hit a pip install snag by forgetting to run Admin. I agree with you, not all users have access to Admin rights so it would be nice to have workarounds.

 

Was trying to hit the Admin error by installing a few libraries  by not running designer as Admin but it looks like the libraries I am testing have all come through without Admin rights (not sure why).

 

Another approach I wanted to test, but much less elegant compared to yours, is to run in command line prompt (without Admin) then run the standard Alteryx.installPackage command in the Python tool after. E.g., doing below in command prompt first:

 

 

python -m pip install openpyxl

 

Will reply in this thread how the two approaches above go, if and when I encounter the same Admin restriction in the future - so I apologize in advance if I end up necroposting here!

haphan_tran
7 - Meteor

Hi @leofrancia,
In our company, users can't open terminal (cmd) without admin rights. But if you want to install Python packages for your terminal, you will want to use Alteryx's Python, which is not in PATH.
If you type: python ..., it will call the python of your computer, which is in PATH.

To do it for Alteryx, you will have to call the full path of Alteryx Python:

C:\"Program Files"\Alteryx\bin\Miniconda3\python -m pip install --user openpyxl 

I explained it briefly in this post as well: Python tool *.yxi offline installer - by pass netw... - Alteryx Community

Labels