From 09c44480fa1a66c589dec846b0e481ac338bf4e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Herculano?= Date: Thu, 5 Jun 2025 17:55:44 -0300 Subject: [PATCH] =?UTF-8?q?mudan=C3=A7as=20relatorio=20ruptura?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- relatório_ruptura/ruptura projetada 23.05.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/relatório_ruptura/ruptura projetada 23.05.py b/relatório_ruptura/ruptura projetada 23.05.py index d1ee1da..420e2ee 100644 --- a/relatório_ruptura/ruptura projetada 23.05.py +++ b/relatório_ruptura/ruptura projetada 23.05.py @@ -13,6 +13,8 @@ from datetime import datetime, time from email.mime.image import MIMEImage +hoje = datetime.today().strftime("%d/%m/%Y") + config = configparser.ConfigParser() config.read(r"C:\Users\joao.herculano\Documents\Enviador de email\credenciais.ini") @@ -147,6 +149,22 @@ df3 = df2[df2['canal'] != "LJ"] df3 = df3.groupby(['uf', 'canal','pdv'])['quantidade_ruptura'].sum().sort_values(ascending=False).reset_index() +df4 = df3.groupby('uf', as_index=False)['quantidade_ruptura'].sum() + +df4['data'] = hoje + +path2 = r'C:\Users\joao.herculano\OneDrive - GRUPO GINSENG\Documentos\acompanhamentos\estudo ruptura\AcompanhamentoRuptura.xlsx' + +# Tenta abrir e escrever com append +with pd.ExcelWriter(path2, mode='a', engine='openpyxl', if_sheet_exists='overlay') as writer: + # Encontra a última linha preenchida + book = writer.book + sheet = writer.sheets['Sheet1'] if 'Sheet1' in writer.sheets else writer.book.active + start_row = sheet.max_row + + # Escreve sem cabeçalho se não for a primeira linha + df4.to_excel(writer, index=False, header=not start_row > 1, startrow=start_row) + with pd.ExcelWriter(excel_path, engine='openpyxl') as writer: df2.to_excel(writer, sheet_name='Detalhado', index=False) df3.to_excel(writer, sheet_name='Resumo', index=False)