AnalystPath

Daily Net Inventory Movement

PandasMediumMid level~10 min

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.

movements
move_daydirectionunits
2021-09-01inbound10
2021-09-01outbound8
2021-09-02inbound15
2021-09-02outbound15
2021-09-03inbound20

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 movements

Solve 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

Related Pandas questions