import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
url = 'https://raw.githubusercontent.com/alura-cursos/python_dados/refs/heads/main/Dados/dados_automoveis.csv'
df_automoveis = pd.read_csv(url)
df_automoveis.head()
esstilo_valor = df_automoveis.groupby('Estilo')['Valor($)'].mean().reset_index().sort_values('Valor($)', ascending = False)
esstilo_valor.head()
fig, ax = plt.subplots(figsize = (10,6))
ax = sns.barplot(data = esstilo_valor, x = 'Valor($)', y = 'Estilo')
ax.set_title('Valores médios de automoveis por estilo',loc = 'left', fontsize = 18, pad = 20)
ax.set_ylabel('')
ax.set_xlabel('')
ax.set_xticklabels([])
ax.tick_params(axis='both', which='both', length=0)
ax.set_frame_on(False)
for container in ax.containers:
labels = [f'R$ {valor.get_width()/1000:,.2f} mil '.replace(',','.') for valor in container]
ax.bar_label(container, label_type='edge', labels = labels, size = 10, fontweight = 'bold')
plt.show()