I currently have a simple python script that reads xlsx file and make calculations based on various different criterias, then split out the results from the various different calculation.
I’m struggling to get this into n8n at the moment (getting help with AI), it seems to indicate that i need Microsoft Excel API to extract data.
On top of that, i wasn’t sure if i should be using javascript or python (as it’s beta).
What is the error message (if any)?
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
I will share part of the workflow if needed as I’m still trying to figure out how to automate this as I usually have to get the excel file, put it into the folder and then run the python script, which is the stuff im trying to automate.
Share the output returned by the last node
Information on your n8n setup
n8n version: 1.103.1
Database (default: SQLite):
n8n EXECUTIONS_PROCESS setting (default: own, main): own
Is there anything in the current process (simple python script) that doesn’t work for you? Is it not working? What are the reasons behind re-implementing this in n8n? Don’t get me wrong, I support you in doing so, I just want to understand what problem you are trying to solve, which requires you to move to n8n.
Partly, it’s to learn n8n with existing task and automate it. Currently, I’m downloading these files and run the python files, but i think going forward, I want to just send these files or anyone can actually send these files to a mailbox or telegram and the n8n can actually pick that up and then send the output to my email, so I don’t need to have my laptop running with the python code and the environment properly setup.
As I have quite a few python code that i need to move to n8n and i can then run it from anywhere without my laptop etc. I also have another python script base on xero-python-oauth2-starter to create invoices with excel output from another app, that i’m looking to see how i can automate this by either emailing or telegram the xlsx file.
I will give that a go and see how far I can get. So, currently my python code is using libraries like pandas to read excel file (which is replaced by the above extra from file node), it creates a data frame and from there i can create filter and then required calculation and so on. Some code snippets as follows:
# Combine conditions using OR operator
filter_condition = conditions[0]
for condition in conditions[1:]:
filter_condition |= condition
# Filter the DataFrame
filtered_df = self.df_service_duty[filter_condition]
# Further filter if only_include_verified_entries is True
if only_include_verified_entries:
filtered_df = filtered_df[filtered_df['Planned Rate Value'] > 0]
# Sum the specified column for filtered rows
sum_values = filtered_df[sum_column_name].sum()
return sum_values
What’s the best practice to implement this? e.g. maintainability and also if there’s an easy way that I can have it as a set parameter, I can easily “copy paste” the code to be reused (and maybe with an adapter of some sort), so that I can easily test the code in python and also straight to n8n (not sure if this is the standard practice).
The conditional logic for filtering is much more robust in pandas, n8n is not a mathematical dataframe engine, the filtering/sorting approach will me more verbose and will require more action on the canvas. Depending on the complexity of the conditionals, this may or may not be easy to implement and will definitely not going to be anywhere near as fast.
Some good news, pandas can be executed in n8n, take a look at the following example: