NostalgiaIndex
Compute and hold the nostalgia index for one or more topics.
Usage
NostalgiaIndex(
window=28,
baseline_months=12,
spike_factor=3.0,
)Parameters
window: int = 28-
Rolling-median window in days (default 28).
baseline_months: int = 12-
Number of months at the start of the series used to define 100.
spike_factor: float = 3.0- Multiple of the trailing 90-day median that counts as a “revival event”.
Examples
>>> import pandas as pd
>>> d = pd.date_range("2016-01-01", periods=730)
>>> v = pd.DataFrame({"date": d, "article": "A", "views": 100})
>>> t = pd.DataFrame({"date": d, "views": 1_000_000})
>>> NostalgiaIndex().compute(v, t).nostalgia_index.iloc[-1]
np.float64(100.0)Methods
| Name | Description |
|---|---|
| compute() | Normalize views by project traffic, smooth, and scale to the baseline. |
| revivals() |
Days where the raw index exceeds spike_factor x the trailing 90-day median.
|
| summary() | Per-topic: current index, all-time peak date, % change vs baseline, revival count. |
compute()
Normalize views by project traffic, smooth, and scale to the baseline.
Usage
compute(views, totals)Parameters
views: pd.DataFrame-
Columns
date,article,views. totals: pd.DataFrame-
Columns
date,views(project-wide totals).
Returns
pd.DataFrame-
Columns
date,article,views,total_views,views_per_million,smoothed,nostalgia_indexandraw_index(unsmoothed, used for revival detection).
revivals()
Days where the raw index exceeds spike_factor x the trailing 90-day median.
Usage
revivals(index_df)Parameters
index_df: pd.DataFrame- Output of compute().
Returns
pd.DataFrame-
Columns
date,article,raw_index,trailing_median,multiple.
summary()
Per-topic: current index, all-time peak date, % change vs baseline, revival count.
Usage
summary(index_df)Parameters
index_df: pd.DataFrame- Output of compute().
Returns
pd.DataFrame-
Columns
article,current,peak,peak_date,pct_vs_baseline, revivals.