Join on differently named keys
Given `orders` with columns `order_id`, `customer`, `amount`, `status` and `placed`, and `people` with columns `handle` and `city`, join `customer` to `handle` and return `order_id` and `city` for the orders whose customer is known, sorted by `order_id` ascending.
Implement
orders_with_city(orders: dataframe, people: dataframe) → dataframeExamples
in
[{"__df__":[{"amount":120.5,"placed":"2024-01-05","status":"paid","customer":"ada","order_id":1},{"amount":80,"placed":"2024-01-07","status":"refunded","customer":"bo","order_id":2},{"amount":45.25,"placed":"2024-02-11","status":"paid","customer":"ada","order_id":3},{"amount":200,"placed":"2024-02-14","status":"paid","customer":"cy","order_id":4},{"amount":15.75,"placed":"2024-03-02","status":"pending","customer":"bo","order_id":5},{"amount":60,"placed":"2024-03-19","status":"paid","customer":"ada","order_id":6}]},{"__df__":[{"city":"Oslo","handle":"ada"},{"city":"Lima","handle":"cy"}]}]out[{"city":"Oslo","order_id":1},{"city":"Oslo","order_id":3},{"city":"Lima","order_id":4},{"city":"Oslo","order_id":6}]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 12 min
solution.py
InputExpectedGot
[{"__df__":[{"amount":120.5,"placed":"2024-01-05","status":"paid","customer":"ada","order_id":1},{"amount":80,"placed":"2024-01-07","status":"refunded","customer":"bo","order_id":2},{"amount":45.25,"placed":"2024-02-11","status":"paid","customer":"ada","order_id":3},{"amount":200,"placed":"2024-02-14","status":"paid","customer":"cy","order_id":4},{"amount":15.75,"placed":"2024-03-02","status":"pending","customer":"bo","order_id":5},{"amount":60,"placed":"2024-03-19","status":"paid","customer":"ada","order_id":6}]},{"__df__":[{"city":"Oslo","handle":"ada"},{"city":"Lima","handle":"cy"}]}][{"city":"Oslo","order_id":1},{"city":"Oslo","order_id":3},{"city":"Lima","order_id":4},{"city":"Oslo","order_id":6}]not run yetsample