July 2019
Beginner to intermediate
740 pages
16h 52m
English
We've already discussed creating lagged data with the shift() method. However, often, we are interested in how the values change from one day to the next. For this, pandas has the diff() method. By default, this will calculate the change from period t to period t+1; however, we can pass an alternate value to diff() when we call it:

Note that this is equivalent to subtracting the result of shift() from the original data:
>>> (... fb.drop(columns='trading_volume') ... - fb.drop(columns='trading_volume').shift()... ).equals(... fb.drop(columns='trading_volume').diff()... )True
We can use diff() to easily calculate the day-over-day ...
Read now
Unlock full access