C10-Brazilian-e-commerce-modeling-team / brazilian-e-commerce

0 stars 6 forks source link

feat: Graph 3. Top 5 best-selling products performance in the 3 main brazilian States #63

Closed leopensaa closed 2 years ago

leopensaa commented 2 years ago

💡 Goal

Show the performance of the 5 best-selling products in the 3 most important States by volume of orders and highest profits.

🤝 Acceptance Criteria

See the Notion reference with pictures as example

felipesaldata commented 2 years ago

Here is my contribution to the charts required:

df_state_treemap = products_df[['order_id','purchase_year','price','product_category_name_english','customer_state']]
df_state_treemap = df_state_treemap.groupby(['customer_state','product_category_name_english'],as_index=False).agg({'price':['sum','count']})
df_state_treemap = df_state_treemap.groupby('customer_state').head(5).reset_index(drop=True)
df_state_treemap.columns =list(map(''.join, df_state_treemap.columns.values)) # to integrate the pricesum and pricecount columns from multiindex to single index
df_state_treemap

#Total revenue
fig = px.treemap(df_state_treemap,path=['customer_state','product_category_name_english'],values='pricesum',color='product_category_name_english')
fig.show()

Image

# amount of orders
fig = px.treemap(df_state_treemap,path=['customer_state','product_category_name_english'],values='pricecount',color='product_category_name_english')
fig.show()

Image

felipesaldata commented 2 years ago

keep total revenue for treemap, add top 3 states and incluide with text number of sales

felipesaldata commented 2 years ago

Top 3

df_state_treemap = products_df[['order_id','purchase_year','price','product_category_name_english','customer_state']]
df_state_treemap_3_states = df_state_treemap.groupby(['customer_state','product_category_name_english'],as_index=False).agg({'price':['sum','count']})
df_state_treemap_3_states.columns =list(map(''.join, df_state_treemap_3_states.columns.values))
df_state_treemap_3_states = df_state_treemap_3_states.sort_values(by='pricesum', ascending=False)
df_state_treemap_3_states = df_state_treemap_3_states.groupby('customer_state').head(5).reset_index(drop=True)

top_3 = df_state_treemap_3_states.groupby('customer_state').sum().sort_values('pricesum', ascending=False).head(3).index
df_state_treemap_3_states = df_state_treemap_3_states[df_state_treemap_3_states.customer_state.isin(top_3)]

image

leopensaa commented 2 years ago

Done! Thank you @felipesaldata