I have written DataCheck
function in data_check.py
for data manipulation of many excel files, which has code structure as follows:
import pandas as pd
def DataCheck(filePath):
df = pd.read_excel(filePath)
try:
df = df.dropna(subset=['building', 'floor', 'room'], how = 'all')
...
...
...
df.to_excel(writer, 'Sheet1', index = False)
if __name__ == '__main__':
status = True
while status:
rawPath = input(r"")
filePath = rawPath.strip('\"')
if filePath.strip() == "":
status = False
DataCheck(filePath)
For the next step I want to repetively browser excel files and pass their paths to DataCheck
using tkinter, the code below named main_app.py
works only for one file then need to restart main_app.py
for another file.
Option 1:
import tkinter as tk
from data_check import DataCheck
from tkinter import filedialog
import os
root = tk.Tk()
root.withdraw()
def open_file(path):
curr_dir = os.getcwd()
temp_dir = filedialog.askopenfilename(parent = root, initialdir = curr_dir, title = 'select file')
return temp_dir
if __name__ == '__main__':
status = True
while status:
DataCheck(path)
Option 2:
import tkinter as tk
from data_check import DataCheck
from tkinter import filedialog
import os
root = tk.Tk()
root.withdraw()
curr_dir = os.getcwd()
root.update()
temp_dir = filedialog.askopenfilename(parent = root, initialdir = curr_dir, title = 'select file')
if __name__ == '__main__':
DataCheck(path)
How could I modify and improve the code above? Sincere thanks.