Daily Failed-Delivery Rate
Problem
A food-delivery platform logs every order, plus a flag marking whether each customer and each courier account is suspended.
DataFrame: `orders` (from `orders.csv`)
| Column | Type |
|-------------|--------|
| order_id | int |
| customer_id | int |
| courier_id | int |
| outcome | object |
| order_day | object |
`outcome` is one of `'delivered'`, `'failed_courier'`, `'failed_customer'`.
DataFrame: `accounts` (from `accounts.csv`)
| Column | Type |
|--------------|--------|
| account_id | int |
| suspended | object |
| account_kind | object |
`suspended` is `'yes'` or `'no'`; `account_kind` is `'customer'` or `'courier'`.
An order **counts** only if **both** its customer and its courier accounts are not suspended. The **failed rate** for a day is the number of counted orders that were not delivered divided by the total number of counted orders that day.
Write a function that reports, for each `order_day` from `'2024-02-01'` through `'2024-02-03'` that has at least one counted order, the day and its failed rate rounded to two decimals. Return columns `order_day` and `fail_rate`, in any order.
Input data
Example rows — the live problem includes the full dataset.
| order_id | customer_id | courier_id | outcome | order_day |
|---|---|---|---|---|
| 1 | 1 | 10 | delivered | 2024-02-01 |
| 2 | 2 | 11 | failed_courier | 2024-02-01 |
| 3 | 3 | 12 | delivered | 2024-02-01 |
| 4 | 4 | 13 | failed_customer | 2024-02-01 |
| 5 | 1 | 10 | delivered | 2024-02-02 |
| account_id | suspended | account_kind |
|---|---|---|
| 1 | no | customer |
| 2 | yes | customer |
| 3 | no | customer |
| 4 | no | customer |
| 10 | no | courier |
Expected output
Your answer should return 3 rows with the columns order_day, fail_rate.
Starter code (Pandas (Python))
import pandas as pd
def daily_fail_rate(orders: pd.DataFrame, accounts: pd.DataFrame) -> pd.DataFrame:
# Your code here
return ordersSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock