In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests after December 31, 2025. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

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

Macros using Python

Sivarubiny
5 - Atom

Hi I am trying to create a macro using python code which will perform text to column and then rows.

I have written the code in python however my input is not getting processed. 

My code doesn't the input value I give through action

My code:

#################################
# List all non-standard packages to be imported by your
# script here (only missing packages will be installed)
from ayx import Package
#Package.installPackages(['pandas','numpy'])


#################################
from ayx import Alteryx
df=Alteryx.read('#1')
x=Alteryx.read('#2')
y=Alteryx.read('#3')

 

#################################
import pandas as pd


#################################
split=df[x].str.split(y,expand=True).add_prefix(x)
split


#################################
combine=pd.concat([df, split],axis=1)
combine


#################################
texttoRow=pd.melt(combine[combine.columns], id_vars=combine[df.columns]).dropna(axis=0,subset=['value'])
texttoRow


#################################
Alteryx.write(texttoRow,1)

2 REPLIES 2
MatthewO
Alteryx Alumni (Retired)

Hello @Sivarubiny:

 

The Python Tool can only read incoming data connections using the Alteryx.read() method. You could configure the Action tools to update specific variables in your code but I have attached a screenshot of a solution that will be simpler to implement. If you configure the Interface tools to update a cell in a Text Input tool, you can then read the values in as panda data frames.

 

python_macro.PNG

alberto_herni
9 - Comet

If you want to get rid off the python error no valid metadata you can encapsulate the python script into a macro following the steps I describe in this article: Python macros in Alteryx, how to get rid of the valid metadata error | by Alberto Hernández | Medium

Labels
Top Solution Authors