What I'm trying to accomplish:
- Having a user drop an excel file/files into a network folder.
- They then must run a python script that will take any files within the network folder (all of which are formatted the same) and append them to the bottom of a master excel file.
- The script will then move the newly appended files to a separate folder.
What I've accomplished thus far:
- I have wrote a script that when executed will take the files from within the folder and append them to the existing master excel file.
My issue:
- Upon appending the files to the master excel, the script gets rid of my table inside of the master file.
- I am wanting to append the new data to the bottom of the table and have it be incorporated into the table.
I have not yet coded anything to move the new files to a new folder but I don't foresee that being an issue. I am a beginner and am just learning python, so go easy. Any help would be very much appreciated. Thank you!
import glob
import pandas as pd
# File locations
location = "T:\\Example\\Test\\*.xlsx"
excel_files = glob.glob(location)
master = "T:\\File\\file.xlsx"
# Create data frames and concatenate files to master
df1 = pd.DataFrame()
df3 = pd.read_excel(master)
for excel_file in excel_files:
df2 = pd.read_excel(excel_file)
df1 = pd.concat([df1, df2])
df4 = pd.concat([df3, df1])
df4.to_excel("T:\\File\\file.xlsx", index=False)