Analyze trends and reconcile results
Calculate grouped metrics, track coverage, and explain differences between views.
On this page
Use the correct denominator and coverage
Choose usable rows for each question. Overall sales can include a usable amount on a row with no readable date. Monthly sales need both. Averages also need an explicit denominator, such as transactions with usable totals.
Reconcile overall and dated totals
Use the cleaned frame from the previous guide. The difference here is one usable amount with an unreadable date. The equality check is approximate so it also works with small floating-point rounding differences.
from math import isclose
# Continue from the cleaned store sales example.
dates = pd.to_datetime(clean["Transaction Date"], format="%Y-%m-%d", errors="coerce")
overall = clean["sales"].sum()
dated = clean.loc[dates.notna(), "sales"].sum()
excluded = clean.loc[dates.isna(), "sales"].sum()
print(float(overall), float(dated), float(excluded))
assert isclose(overall, dated + excluded)
Example output
67.0 65.0 2.0