We need to pass the file path dynamically to the python code, but I'm not getting the correct approach.
I want to give the file path via input text tool in Gallery and pass that into python code and read the file. Could you please help to build it.
Solved! Go to Solution.
@dineshbabu2811 I can advise two things.
(1) To pass the file path 'dynamically' to the Python tool, you need to configure the Interface tool on Input Text tool so that user can select folders by themselves.
(2) Delimiter of directory is slash '/' in Python code(C:user/hoge/hogehoge), while it's back slash '\' in Alteryx(C:user\hoge\hogehoge). Usually you need to configure the step to replace \ to / in file path somewhere. I always put the Formula tool with Replace([Filepath], "\", "/") function before loading file path to the Python tool.
@gawaI have replaced the "/" and tried to call the column FilePath in python, its not working.
Please see the attached screenshot and advise me how to call the file based on the user input.
It says...
@dineshbabu2811 --- these are Python issues. FilePath in that case would be a variable. If you want it as a column name it would be 'FilePath' --- make sure you are importing Pandas.
@gawa @apathetichell Fixed the issue by using the below code and passing the values dynamically with interface Text tool.
from ayx import Package
import pandas as pd
from ayx import Alteryx
pth= Alteryx.read("#1")
Filename = pth['FilePath'].iloc[0]
Alteryx.write(pth, 1)
df=pd.read_csv(Filename, encoding = 'latin1')
cols=df.head(2)
Alteryx.write(cols, 2)
@dineshbabu2811 you should accept @gawa 's solution - and mine if you're feeling generous.