Aug-21-2023, 10:16 AM
Hello everyone,
I'm new to development. I tried coding a script that works perfectly fine using Python, but I need to convert it to an exe so that my other colleagues can use it.
When I attempt to convert it using "auto-py-to-exe," I encounter this error: "IndexError: tuple index out of range," and I'm struggling to resolve it.
Here's the code I'm using:
I'm new to development. I tried coding a script that works perfectly fine using Python, but I need to convert it to an exe so that my other colleagues can use it.
When I attempt to convert it using "auto-py-to-exe," I encounter this error: "IndexError: tuple index out of range," and I'm struggling to resolve it.
Here's the code I'm using:
import tkinter as tk from tkinter import filedialog import pandas as pd # Function to load and process the XLSX file def process_xlsx(): file_path = filedialog.askopenfilename(filetypes=[("XLSX files", "*.xlsx")]) if file_path: df = pd.read_excel(file_path) # Replace null (NaN) values with an empty string in the "Description" column df['Description'] = df['Description'].fillna("") # List of words to filter out in the "Hostname" and "Description" columns words_to_remove_hostname = ["ALCATEL", "Galaxy", "EPW", "ETW", "EFW", "router", "HSRP", "8028"] words_to_remove_description = ["router", "HSRP", "Router", "WIDIS"] # Filter rows with keywords to remove in the "Hostname" and "Description" columns hostname_filter_condition = ~df['Hostname'].str.contains('|'.join(words_to_remove_hostname)) description_filter_condition = ~df['Description'].str.contains('|'.join(words_to_remove_description)) df = df[hostname_filter_condition & description_filter_condition] # Create a new "VLAN" column by extracting the VLAN number after the dot df['VLAN'] = df['Vlan'].str.split('.').str[-1] # Create a "Group" column with the first 5 characters of the hostname df['Group'] = df['Hostname'].str[:5] # Separate VLAN 1000 devices and others into two DataFrames df_vlan_1000 = df[df['VLAN'] == '1000'].copy() # Using .copy() df_other = df[(df['VLAN'] != '1000') & (df['VLAN'] != '99')].copy() # Exclude VLAN 1000 and 99 # Remove the Vlan column which is no longer needed df_vlan_1000.drop(columns=['Vlan'], inplace=True) df_other.drop(columns=['Vlan'], inplace=True) # Sort the DataFrames by group and VLAN df_vlan_1000.sort_values(by=['Group', 'VLAN'], inplace=True) df_other.sort_values(by=['Group', 'VLAN'], inplace=True) # Write the DataFrames to an XLSX file with two sheets "VLAN_1000" and "Other" result_file_path = "Naming_Plan.xlsx" with pd.ExcelWriter(result_file_path) as writer: df_vlan_1000.to_excel(writer, sheet_name="VLAN_1000", index=False) df_other.to_excel(writer, sheet_name="Other", index=False) status_label.config(text="Data grouped by VLAN successfully.") # Create the main window root = tk.Tk() root.title("Grouping Data by VLAN") # Button to load and process the XLSX file load_button = tk.Button(root, text="Load and Group by VLAN", command=process_xlsx) load_button.pack(pady=20) # Label to display status status_label = tk.Label(root, text="") status_label.pack() # Start the main interface loop root.mainloop()Thank you for your help