from IPython.display import display
custo_por_categoria = df.groupby('categoria')[['custo_empacotamento','custo_envio','custo_produto']].sum()
custo_por_categoria['custo_total'] = custo_por_categoria.sum(axis=1)
custo_por_categoria = custo_por_categoria.sort_values('custo_total', ascending=False).reset_index()
estilizacao = (
custo_por_categoria.style
.format({
'custo_empacotamento': 'R$ {:,.2f}',
'custo_envio': 'R$ {:,.2f}',
'custo_produto': 'R$ {:,.2f}',
'custo_total': 'R$ {:,.2f}'
})
.background_gradient(subset=['custo_total'], cmap='Blues')
.apply(lambda col: ['font-weight: bold' if v==col.max() else '' for v in col], subset=['custo_total'])
.set_caption("Custos por Categoria - Acumulado")
)
display(estilizacao)