Reading locally stored XML files in Python (Jupyter) with Alteryx
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi Everyone! This being my first community post, very excited to learn from all your experiences 🙂
I wrote a python script to iteratively parse an XML File to an excel table (csv) for further Alteryx analysis. I want to modify my use case to incorporate this parsing logic within a single canvas itself (instead of first running my python script separately and then plugging the resulting csv into my canvas).
I was hoping to achieve this by using the Python tool, but as I understand the tool reads all inputs as a pandas dataframe by default and this causes incompatibility with my parsing script as I make use of the "xml" python library that directly deals with an input XML file.
I was wondering if there was any way in which I can directly read the XML file stored locally, in my Jupyter notebook within Alteryx and replicate my script.
Any suggestions would be greatly appreciated and do let me know in case any further details are required, thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
The input on the Python tool is optional, so you can use it as the first tool in a stream of tools. At the end of your script, change it so that instead of writing to a csv, convert the table to a data frame and send it to the Python tool output using Alteryx.write(df,1). This will make it available for further processing in the workflow.
For a bit of added flexibility, you could use a text input to pass in the name of the file to the Python tool.
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Thanks @danilang
Thing is I tried this approach and kept getting an error thrown as - "File not found" which I'm assuming corresponds to the jupyter notebook/python tool not being able to read my XML file stored locally in the same location as the canvas.
This got me wondering if reading locally stored files is possible at all through this tool. If so, could you maybe share an example of how one could read a locally stored file directly with the tool without using an input tool?
Thanks,
Agrim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@danilang - never mind: figured out the mistake I was making. Hadn't accounted for the fact that the current working directory of Alteryx is set by default and would point to the workflow constant "Engine Temp Path".
Just used the below to temporarily change the file path in the jupyter notebook itself :
import os
os.getcwd() # this shows me the path Alteryx is reading in, initially - no wonder it wasn't able to read in my input file!
os.chdir(target_path) #this changes to the path in which my file is stored in and so it ends up working seamlessly 🙂
Thanks for your help - Accepting your solution as it pointed me in the right direction 🙂
Regards,
Agrim
