So I'm trying to create a very basic python UI where a user uploads a CSV with a list of cities and the program creates an inner join with a pre-existing database of zip codes returns a list of cities and their corresponding zip codes. My code is functional so far. I'd just like the user to be able to upload a CSV from anywhere in their system. Right now, the program only reads from the python directory. I don't want to have to specify the file path of the input file. Is there any way this can be done? Here's the code I have right now -
import tkinter as tk
from tkinter import filedialog
import pandas as pd
root= tk.Tk()
canvas1 = tk.Canvas(root, width = 300, height = 300, bg = 'lightsteelblue2', relief = 'raised')
canvas1.pack()
def getCSV():
global cities
import_file_path = filedialog.askopenfilename()
cities = pd.read_csv('cities.csv')
zips = pd.read_csv('zips.csv')
output = pd.merge(cities, zips, on='state' and 'county', how='inner')
output.to_csv('output.csv', encoding='utf-8', index=False)
browseButton_CSV = tk.Button(text=" Upload City Data & Close ", command=getCSV, bg='green', fg='white',
font=('helvetica', 12, 'bold'))
canvas1.create_window(150, 150, window=browseButton_CSV)
root.mainloop()
I'm kinda new to python and programming in general. Just been learning it over the past month or 2. Any help is appreciated!
Thanks, DJ