Daily Net Inventory Movement
Problem
A warehouse logs how many units moved in and out of stock each day.
DataFrame `movements` (from `movements.csv`) has columns `move_day` (date), `direction` (either `'inbound'` or `'outbound'`), and `units`. Each row gives the total units moved in that direction on that day; `(move_day, direction)` is unique.
For each day, report the net change in stock, defined as inbound units minus outbound units. Name the column `net_change` and order the result by `move_day`.
Input data
Example rows — the live problem includes the full dataset.
| move_day | direction | units |
|---|---|---|
| 2021-09-01 | inbound | 10 |
| 2021-09-01 | outbound | 8 |
| 2021-09-02 | inbound | 15 |
| 2021-09-02 | outbound | 15 |
| 2021-09-03 | inbound | 20 |
Expected output
Your answer should return 4 rows with the columns move_day, net_change.
Starter code (Pandas (Python))
import pandas as pd
def daily_net_movement(movements) -> pd.DataFrame:
# Your code here
return movementsSolve 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