I'm trying to get Python to export an xlsx file but give me a dialogue box to define the new filename / destination. I have managed to do it to select the initial file to load but unable to work out how to apply this to the processed file:
Currently: dialogue box to select file for Python to process > Python runs the process > exports to a folder/file I've typed into the script.
What I'm trying to do: dialogue box to select file for Python to process > Python runs the process > dialogue box to select destination path and new filename.
#!/usr/bin/env python3 import pandas as pd from openpyxl import load_workbook
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw() # This hides the main window
file_path = filedialog.askopenfilename()
print(file_path)
for PANDA CODE:
df = pd.read_excel(file_path)
print(df)
print(df[['Goal Time seconds SERIE B', 'Country SERIE B', 'Match Date SERIE B',]])
df.rename(columns={'Goal Time seconds SERIE B': 'GoalOccurrenceSeconds','Country SERIE B': 'Country', 'Match Date SERIE B': 'MatchDate'}, inplace=True)
print(df[['GoalOccurrenceSeconds', 'Country', 'MatchDate']])
print(df)
data = pd.DataFrame(df[['Country', 'GoalOccurrenceSeconds','MatchDate']])
print(df)
data.to_excel("output1.xlsx", index=False)
#This re-loads the said excel doc ready for 2nd pass at changes.
workbook = load_workbook('output1.xlsx')
sheet = workbook.active
column_to_modify = 'A'
for row in range(2, sheet.max_row + 1):
cell = sheet[f"{column_to_modify}{row}"]
if cell.value == 'ITA':
cell.value = 'TRUE'
elif str(cell.value) != 'ITA':
cell.value = 'FALSE'
This is the bit i can't figure out - to use dialogue box to select folder/filename.
workbook.save('/Users/OUTPUTS/myfilename.xlsx')
Any help gratefully appreciated