Want to combine a few excel files into One Excel File and in 1 worksheet.
Puesdo-code:
1 create new workbook to hold all new excel files
2 want to be able to run a loop which takes in excel files and converts them all into dataframes
3 writes all files into that newly created workbook skipping one column for each new file written next to it.
Inital Attempt
# Combining dataFrames in excel
excelName = input("Label your excel file: ")
xlsxAUTO = '.xlsx'
excelAutoNamed = excelName + xlsxAUTO
writer = pd.ExcelWriter(excelAutoNamed,engine='xlsxwriter')
wbook = 0
for excel_file in excel_files:
Currentwb = load_workbook(excel_file)
Currentsheet = Currentwb.worksheets[0]
MaxCols = Currentsheet.max_column
print(MaxCols)
df2 = pd.DataFrame()
df2 = pd.read_excel(excel_file)
if wbook == 0:
MaxCols = 0
print(wbook)
df2.to_excel(writer,sheet_name='Validation',startrow=0, startcol=MaxCols+10)
writer.save()
wbook = wbook+1
print(wbook)
Note: the # of columns vary for each excel file, as such the parameter for startCol should be generated from the following:
1get the max column number/letter from the previous dataframe and store that in a temp variable. assign that to the startCol parameter.
2Once again, I dont want them stacked one over another, just next to each other, so the axis=1 trick may/maynot work.
EDIT for bold format changes original vs new original excel file vs newly generated excel file