Closed leopensaa closed 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()
# 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()
keep total revenue for treemap, add top 3 states and incluide with text number of sales
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)]
Done! Thank you @felipesaldata
💡 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