I have an Excel file that contains a column with header 'Original Translation'. I also have a DataFrame with column 'Original Translation - {language}', based on the language I am using and some manipulations.
My goal is to open the Excel file, write over the column with header 'Original Translation' with all the data from my DataFrame column 'Original Translation - {language}', preserve the original Excel file formatting, and save to a new output folder.
Here is the code I currently have:
def output_formatted_capstan_file(df, original_file, country, language):
# this is where you generate the file:
# https://stackoverflow.com/questions/20219254/how-to-write-to-an-existing-excel-file-without-overwriting-data-using-pandas
try:
print(original_file)
book = load_workbook(original_file)
writer = pd.ExcelWriter(original_file, engine='openpyxl')
writer.book = book
df.to_excel(writer, ['Original Translation - {}'.format(language)])
writer.save()
except:
print('Failed')