pasholnahuy

Untitled

Nov 3rd, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. def task_2(orders, reviews):
  2.  
  3. df = orders.merge(reviews, on = 'order_id')
  4. df['order_delivered_carrier_date'] = pd.to_datetime(df['order_delivered_carrier_date']).dt.date
  5.  
  6. df['order_delivered_carrier_date'].dropna(inplace = True)
  7. df.drop_duplicates()
  8. grouped_df = df.groupby(['order_delivered_carrier_date', 'order_status']).agg({'order_id':'count'}).reset_index()
  9. grouped_df.rename(columns = {'order_id': 'order_count', 'order_delivered_carrier_date': 'date'}, inplace = True)
  10. fig = px.histogram(grouped_df, x= "date", y = "order_count", color="order_status", histfunc="avg")
  11. fig.update_layout(
  12. xaxis_rangeslider_visible=True
  13. )
  14. fig.show()
  15. my_reviews = copy.deepcopy(reviews)
  16. my_reviews['review_answer_timestamp'] = pd.to_datetime(my_reviews['review_answer_timestamp']).dt.date
  17. grouped_reviews = my_reviews.groupby(['review_answer_timestamp']).agg({'review_score':'mean'}).reset_index()
  18. grouped_reviews.rename(columns = {'review_answer_timestamp' : 'review_date'}, inplace = True)
  19.  
  20. fig2 = px.histogram(grouped_reviews, x= "review_date", y = 'review_score', histfunc = 'avg')
  21. fig2.update_layout(
  22. xaxis_rangeslider_visible=True
  23. )
  24. fig2.show()
Add Comment
Please, Sign In to add comment