Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_df(sellers, items, products, orders):
- merged_df = sellers.merge(items, on = 'seller_id')
- df = products.merge(merged_df, on = 'product_id')
- df = df[['seller_state', 'product_category_name', 'order_id']].merge(orders[['order_status', 'order_id', 'order_delivered_customer_date']], on = 'order_id')
- df.rename(columns = {'product_category_name': 'category', 'seller_state': 'state', 'order_status': 'status', 'order_delivered_customer_date' : 'year'}, inplace = True)
- df['date'] = df['date'].apply(lambda x: pd.to_datetime(x).year)
- return df
- app = Dash(__name__)
- app.layout = html.Div([
- dcc.Graph(id='sellers-graph'),
- dcc.Slider(
- df['year'].min(),
- df['year'].max(),
- step=None,
- value=df['year'].min(),
- marks={str(year): str(year) for year in df['year'].unique()},
- id='year-slider'
- )
- dcc.Checklist(
- df['state'],
- df['state'],
- id = 'state-slider'
- )
- ])
- df = get_df(sellers, items, products, orders)
- @app.callback(
- Output('sellers-graph', 'figure'),
- [Input('date-slider', 'value')
- Input('states-dropdown', 'value'),
- Input('statuses-filter', 'value')])
- def update_figure(time_gap, state_to_display, statuses_filter):
- df = df.groupby(['state', 'category', 'status']).agg({'order_id' : 'count'}).reset_index()
- df.rename(columns = {'order_id' : 'count'}, inplace = True)
- df = df.loc[df.state == state_to_display & df.statys = statuses_filter & df.time_gap]
- fig = px.bar(table_1, y="customer_state", x="count", color="category",
- title="Distribution by sales categories", orientation='h', height=300)
- fig.update_layout(transition_duration=500)
- return fig
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement