0

I'm beginning on python and made a course about sending info about sales using outlook. The teacher didn't align the rows, and I would like to know how to do that. I merged the rows by my own and wanted to know if I can merge all info in 1 line of code. I'm from Brazil, so some of my variables and the email text are in Portuguese

import win32com.client as win32
import pandas as pd

#TABELA_VENDAS == sales_table
tabela_vendas = pd.read_excel('H:\Curso Python\Projeto\Vendas.xlsx')


pd.set_option('display.max_columns', None)
print(tabela_vendas)
print('-' *  50)


#FATURAMENTO == REVENUES
faturamento = tabela_vendas[['ID Loja','Valor Final']].groupby('ID Loja').sum()
print(faturamento)
print('-' *  50)


#QUANTIDADE == QUANTITY
quantidade = tabela_vendas[['ID Loja','Quantidade']].groupby('ID Loja').sum()
print(quantidade)
print('-' *  50)


#TICKET_MEDIO == REVENUES/QUANTITY
ticket_medio = (faturamento['Valor Final'] / quantidade['Quantidade']).to_frame()
ticket_medio = ticket_medio.rename(columns={0: 'Ticket Médio'})
print(ticket_medio)
print('-' *  50)


#MERGING ALL TABLES IN 1
tabela_geral = pd.merge(faturamento, quantidade, how='outer', on='ID Loja')
tabela_geral = pd.merge(tabela_geral, ticket_medio, how='outer', on='ID Loja')
print(tabela_geral)
print('-' * 50)


#SENDING EMAIL
outlook = win32.Dispatch("Outlook.Application")
mail = outlook.CreateItem(0)
mail.To = "********@gmail.com"
mail.subject = 'Relatório de vendas por loja:'
mail.HTMLBody = f'''
<p>Prezados,</p>

<p>Segue o relatório de vendas por loja.</p>

<p>Tabela Geral das Lojas</p>
{tabela_geral.to_html(formatters={'Valor Final': 'R${:,.2f}'.format, 'Ticket Médio': 'R${:,.2f}'.format})}

<p>Qualquer dúvida estou a disposição.</p>

<p>Att.,</p>
<p>Pedro</p>
'''

mail.Send()

print('Email enviado!') #email sent
Jacob Lee
  • 4,405
  • 2
  • 16
  • 37
  • Hi, so are you having trouble centering the rows when displayed (as per the title of your question) or merging them (according to what you explain)? – Laurent Apr 22 '21 at 16:38
  • @Laurent My main focus is centering the rows, but I also wanted to know if I can merge them in 1 line only, instead of 2 lines as I did. – Pedro Bonorino Apr 23 '21 at 14:24
  • To center your rows, this post could help https://stackoverflow.com/a/12985403/11246056F And for the merging, you could refer to this one https://stackoverflow.com/a/44338256/11246056 – Laurent Apr 23 '21 at 15:46

0 Answers0