Advertisement
pasholnahuy

Untitled

Oct 21st, 2023
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. def task_6(orders, customers, items, sellers):
  2. df = orders.merge(items, on = "order_id")
  3. df = df[df["order_status"] == "delivered"]
  4. df["delivery_gap"] = pd.to_datetime(df["order_delivered_customer_date"]) - pd.to_datetime(df["order_purchase_timestamp"])
  5. df = df.merge(customers, on = "customer_id")
  6. df = df.merge(sellers, on = "seller_id")
  7. df = df[["order_id", "customer_state", "seller_state", "delivery_gap", "price", "freight_value"]]
  8. df = df.dropna(subset = ["delivery_gap"])
  9. df["delivery_gap"] = df["delivery_gap"].apply(lambda x: int(x.days))
  10. df["total_price"] = df["price"] + df["freight_value"]
  11. df["other_state"] = df["customer_state"] != df["seller_state"]
  12. df = df.groupby(["order_id", "other_state"]).agg({"delivery_gap":"mean", "total_price":"mean"}).reset_index()
  13. sns.relplot(df, x=df.delivery_gap, y=df.total_price, hue="other_state", legend=True, kind = 'line')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement