Pandasdrill

Level 5: Analysis Exercise 41 of 45 Pro

Change from the previous period

A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.

The task

Return the change in `revenue` from the previous month (this month minus last month), using `shift`. The first month is NaN.

What this exercise teaches

shift(1) lines up last month's revenue next to this month's, and subtracting gives the change. shift(-1) would look one month ahead instead.

A hint if you get stuck

shift(1) moves every value down one row, so each row lines up with the previous period.

This exercise is part of Pro

Pro unlocks all 45 exercises, with worked solutions and progress saved to your account. The free exercises work without an account.

You create a free account first, so Pro is attached to it.

Monthly is charged today and then every month until you cancel, in one click from your account page. Lifetime is one payment with no renewals. Full refund within 14 days of paying.

Start with the free exercises

More exercises in Analysis