Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def task_6(orders, customers, items, sellers):
- df = orders.merge(items, on = "order_id")
- df = df[df["order_status"] == "delivered"]
- df["delivery_gap"] = pd.to_datetime(df["order_delivered_customer_date"]) - pd.to_datetime(df["order_purchase_timestamp"])
- df = df.merge(customers, on = "customer_id")
- df = df.merge(sellers, on = "seller_id")
- df = df[["order_id", "customer_state", "seller_state", "delivery_gap", "price", "freight_value"]]
- df = df.dropna(subset = ["delivery_gap"])
- df["delivery_gap"] = df["delivery_gap"].apply(lambda x: int(x.days))
- df["total_price"] = df["price"] + df["freight_value"]
- df["other_state"] = df["customer_state"] != df["seller_state"]
- df = df.groupby(["order_id", "other_state"]).agg({"delivery_gap":"mean", "total_price":"mean"}).reset_index()
- 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