0
I made this function that receives the destination directory and the month that was generated the reports, I wanted to make it smaller using a for that goes through this list:
ufv_name = ['CB1', 'CB2', 'CB3', 'GM1', 'IM1', 'JD2', 'PIU', 'STR'] #sigla das ufvs
Follows the function:
def unir(dir, mes):
#IMPORTANDO OS RELATORIOS PARA UNIR EM UM SÓ
CB1 = pd.read_excel('{}PR_CB1_{}.xlsx'.format(dir, mes))
CB2 = pd.read_excel('{}PR_CB2_{}.xlsx'.format(dir, mes))
CB3 = pd.read_excel('{}PR_CB3_{}.xlsx'.format(dir, mes))
PIU = pd.read_excel('{}PR_PIU_{}.xlsx'.format(dir, mes))
IM1 = pd.read_excel('{}PR_IM1_{}.xlsx'.format(dir, mes))
STR = pd.read_excel('{}PR_STR_{}.xlsx'.format(dir, mes))
JD2 = pd.read_excel('{}PR_JD2_{}.xlsx'.format(dir, mes))
GM1 = pd.read_excel('{}PR_GM1_{}.xlsx'.format(dir, mes))
with pd.ExcelWriter('{}Relatorio_total.xlsx'.format(dir), engine='xlsxwriter') as writer:
CB1.to_excel(writer, sheet_name='CB1', index = False)
CB2.to_excel(writer, sheet_name='CB2', index = False)
CB3.to_excel(writer, sheet_name='CB3', index = False)
PIU.to_excel(writer, sheet_name='PIU', index = False)
IM1.to_excel(writer, sheet_name='IM1', index = False)
STR.to_excel(writer, sheet_name='STR', index = False)
JD2.to_excel(writer, sheet_name='JD2', index = False)
GM1.to_excel(writer, sheet_name='GM1', index = False)
print('Relatórios Unidos em um só arquivo')
You may notice that imported reports always have the same pattern.
Test this https://ideone.com/uPVSQv code, I did it in my head because I don’t have the files to test.
– Augusto Vasques
I managed to do with your code, thank you very much!
– Lucas Gonçalves e Silva