I have two excel files to import; file1.xls and file2.xls. I have define two separate function to import and third function to merge these files. However, merge is not happening. The error is showing
NameError: Name 'File1' is not defined.
I am using below code. Please help.
from tkinter import messagebox, filedialog, Frame, Button, Tk, Menu
import pandas as pd
def importivl():
global File1
LI_Filepath = filedialog.askopenfilename()
File1 = pd.read_excel(LI_Filepath)
messagebox.showinfo("File1", "File Imported Successfully")
def importcatfile():
global File2
Cat_Filepath = filedialog.askopenfilename()
File2 = pd.read_excel(Cat_Filepath)
messagebox.showinfo("File2", "File Imported Successfully")
def mergeivlcat():
File1 = pd.merge(File1, File2, on = "ID", how = "left")
def phase_one():
frame = Frame(root)
frame.pack()
import_LI_File = Button(root, text = "Import File1", command = importivl).pack()
import_Category_File = Button(root, text = "Import File2", command = importcatfile).pack()
mergeivlcat()
root = Tk()
root.geometry("600x400")
menubar = Menu(root)
filemenu = Menu(menubar, tearoff = 0)
filemenu.add_command(label = "Phase One", command = phase_one)
filemenu.add_separator()
filemenu.add_command(label = "Exit", command = root.destroy)
menubar.add_cascade(label = "File", menu = filemenu)
root.config(menu = menubar)
root.mainloop()