Delivery time by city

null handling

Delivery time by city

Swiggy Pandas Interview Question

Swiggy sets the delivery estimate it shows at checkout city by city: too tight and the order lands late and gets refunded, too loose and the customer orders somewhere else. An order that was canceled never left the restaurant and has no delivery time, so it tells the estimate nothing.

Using the orders DataFrame, find each city, the number of orders that were actually delivered as delivered_orders, and their average delivery time in minutes as avg_minutes, rounded to 1 decimal place. Sort by avg_minutes, slowest first. Assign the answer to result.

Asked of

  • Data Analyst
  • Business Analyst
  • BI Analyst
  • Product Analyst
  • Analytics Engineer
  • Data Scientist

ordersDataFrame32 rows

Column NameType
order_idint64
citystr
restaurant_idint64
placed_atstr
delivery_minutesfloat64
order_totalfloat64
statusstr

ordersExample Input

order_idcityrestaurant_idplaced_atdelivery_minutesorder_totalstatus
4001Bengaluru12024-07-01 12:10:0032540delivered
4002Bengaluru22024-07-01 13:05:0041320delivered
4003Bengaluru12024-07-01 20:15:0028460delivered
4004Bengaluru32024-07-02 12:40:00NULL275canceled
4005Bengaluru22024-07-02 19:20:0036680delivered
4006Bengaluru12024-07-03 13:15:0025390delivered
4007Bengaluru32024-07-03 20:05:0052510delivered
4011Hyderabad42024-07-01 12:30:0038410delivered
4012Hyderabad52024-07-01 19:50:0044295delivered
4013Hyderabad42024-07-02 13:20:0031530delivered
4014Hyderabad62024-07-02 20:40:0058700delivered
4015Hyderabad52024-07-03 12:55:00NULL260canceled
4016Hyderabad62024-07-03 19:35:0049480delivered

Example Output

citydelivered_ordersavg_minutes
Hyderabad544
Bengaluru635.7

Explanation

Hyderabad delivered five orders in the example at 44 minutes on average, slower than Bengaluru's six at 35.7. The canceled order in each city has no delivery time and is kept out of both the count and the average.

The example above is a small slice of the data. Your code runs against the full DataFrames.