Align yesterday's count and compute changes without inventing growth from a zero baseline.
Step 1 of 3 · Learn
Align the previous calendar day
Sort by date before .shift(1). Shift uses the previous row, not a calendar lookup. On a complete daily calendar, that row is yesterday; without the calendar, it could be several days earlier. The first row has no previous value.
index
day
searches
0
Mon
10
1
Tue
0
2
Wed
15
↓
index
day
searches
previous
change
0
Mon
10
NA
NA
1
Tue
0
10
-10
2
Wed
15
0
15
Shift aligns the previous count; diff subtracts it from the current count.
Keep zero-baseline growth missing
.pct_change(fill_method=None) returns fractional change, not a percentage: 0.5 means 50% growth. A zero previous count has no defined relative growth here. Use .where(previous > 0) to leave those rows and the first row missing; a drop from a positive count to zero is -1.
index
searches
0
10
1
0
2
15
3
30
↓
index
searches
growth
0
10
NA
1
0
-1
2
15
NA
3
30
1
Growth from zero stays missing; a fall from 10 to 0 is -100%.
Do not invent earlier activity
Retain every date in the reporting calendar. Do not fill the first prior count with 0 or forward-fill gaps to create a growth rate. For this report, an absent event date has a known count of zero, while the day before the report is unavailable.
▷ Your turn
From daily_searches, return date, searches, and previous_searches in ascending date order. previous_searches is the preceding calendar day's count within this report. Leave it missing on the first date. Preserve UTC timestamps and save the DataFrame as result.
daily_searches contains date and searches for every UTC date from July 6 through August 30, 2026, with 0 on dates without searches. It is built from searches inside that interval; earlier dates are not available for the first comparison or rolling window.