The Python tool is a code editor for users of Python. Proficiency in Python is recommended before using this tool.
While Designer accepts custom Python code, Alteryx does not provide support for it.
The Python tool includes the following more common data science packages:
- ayx: Alteryx API
- jupyter: Jupyter metapackage.
- matplotlib: Python plotting package.
- numpy: NumPy, array processing for numbers, strings, records, and objects.
- pandas: Powerful data structures for data analysis, time series, and statistics.
- requests: Python HTTP for Humans.
- scikit-learn: A set of Python modules for machine learning and data mining .
- scipy: SciPy, Scientific Library for Python .
- six: Python 2 and 3 compatibility utilities.
- SQLAlchemy: Database Abstraction Library.
- statsmodels: Statistical computations and models for Python.
Additional package installation
Depending on what version of Designer you're using, you can install additional packages using Alteryx.installPackages. The example below installs keras.
- Alteryx non-admin installations can install packages without any special permissions.
- Alteryx admin installations must be run in admin mode. If you are unable to run your admin installation in admin mode, you cannot install additional packages.
You cannot use existing Jupyter Notebooks with the tool.
The Python tool accepts multiple inputs. Once inputs are connected, you must run the workflow to cache the incoming data streams.
To access an incoming data connection:
- Import the Alteryx library: from ayx import Alteryx
- Access the connection and provide a variable to use a data reference:
- Use the connection name: Alteryx.read("<connection name>")
from ayx import Alteryx data1 = Alteryx.read("#1")
from ayx import Alteryx data2 = Alteryx.read(Alteryx.getIncomingConnectionNames())
Configure the tool
Run your workflow before beginning to work with the Python tool. Running your workflow caches your data and makes it accessible to the Python tool. Your data is then treated as a pandas data frame. More information about pandas data frames can be found at pandas.pydata.org.
Jupyter Notebook resources
The configuration window interface resembles a Jupyter Notebook. If you are unfamiliar with Jupyter Notebooks, go to Help > User Interface Tour or Help > Notebook Help. For code assistance, see the additional references that are available under the tool's Help option.
Because the tool mimics the Jupyter Notebook interface but is within the constraints of Designer, a number of options have behavior that differs from the expected behavior of a standard Jupyter Notebook.
Logout: Clicking this button does not disconnect from a Jupyter Notebook server. To see that your tool is still functional, click off the tool and back on the tool.
File: Save and Checkpoint and Revert to Checkpoint provide ways to work through potential problems with your code. Rename does not rename the workbook - you can rename the workbook but it does not persist when you click off the tool. All other options do not provide recognized functionality.
Kernel: Interrupt stops processing. All Restart options restart the processing of the interactive environment. Reconnect clears the workbook of intermediate results. Change kernel does not provide functionality. It is recommended that you do not select Shutdown.
Widget: All options do not provide recognized functionality.
- Saving regularly guarantees your code is maintained when you click away from the configuration window. It also provides a checkpoint to revert to if needed. To revert, select File > Revert to Checkpoint and select the checkpoint.
- Create a cell that prints the connection's data to the tool's results window, and leave the cell at the end of your cell list. This guarantees that you present final data in the results window.
Output data from tool
Use Alteryx.write to output data from the tool.
- To send data to other tools on the canvas, use Alteryx.write(<pandas data frame>, <output anchor number>).
- Alteryx.write only accepts pandas data frames. If you have data in another format, use the pandas library to convert it to a pandas data frame. The pandas library is pre-installed with Designer and can be accessed in the Jupyter notebook using import pandas.
- You can send up to five data frames to the output anchors.