Pandas pct_change and resample: Handling Gaps in Time Series Data
Data analyst Michael Nocito published a tutorial on August 8, 2026, explaining how to use pandas functions pct_change() and cumsum() to calculate period-on-period change and running totals from transactional data. A key finding highlighted is that pandas' groupby method only creates rows for periods with existing data, while resample automatically fills in missing calendar periods with zeros. Using a real 16-row orders dataset spanning January to May 2026, the guide demonstrates how a missing April causes groupby to return four rows instead of five, skewing percentage-change calculations. The tutorial also explains an edge case where pct_change() returns infinity when a value rises from zero, since division by zero has no finite result. Nocito recommends resample with a datetime index as the more reliable approach for building regular time series before applying any change or cumulative calculations.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in