Sweetviz: Compare Two Samples Without Hiding Their Sizes

Compare both sample sizes before interpreting the exported feature charts.

Two comparison charts can show the same number of successful records and still describe different proportions. Name both samples and retain their row counts when you export a Sweetviz comparison. The person opening the HTML should be able to recover each percentage from its numerator and denominator.

Use this original fictional exercise: Batch A contains four package checks, with inspection times of 2, 4, 6, and 8 minutes. Two checks were completed on the first attempt. Batch B contains three checks, taking 3, 9, and 18 minutes; two were completed on the first attempt. These are invented teaching records, not operational measurements.

Fictional sample comparison: four checks versus three; native Sweetviz export available
Fictional sample comparison: four checks versus three; native Sweetviz export available
Open the full example ↗

Open the complete example · Download the full HTML source

Start with the comparison you want someone to read

Both batches contain two first-attempt completions. Their rates are 2/4, or 50%, and 2/3, or approximately 66.7%. Batch A's mean inspection time is 20/4 = 5 minutes; Batch B's is 30/3 = 10 minutes. Keep the minutes label in the field name so the exported report carries the unit.

The difference in completion rates is approximately 16.7 percentage points, using these two denominators. It does not establish that a change in process caused the difference. The exercise supplies neither a sampling design nor an explanation of how the batches were assigned.

This is a comparison report rather than a formatted list of individual records. If the recipient primarily needs to inspect each line and a subtotal, use the existing pandas DataFrame HTML report. Here the task is to read two distributions while keeping their sample sizes visible.

Generate the report from both DataFrames

Sweetviz's maintained public comparison function accepts a source DataFrame and a comparison DataFrame. Give each a readable name. The example deliberately disables pairwise analysis: the task needs two feature summaries, not an additional association matrix.

from pathlib import Path
import pandas as pd
import sweetviz as sv

a = pd.DataFrame({
    "Inspection minutes": [2, 4, 6, 8],
    "First attempt": [True, False, True, False],
})
b = pd.DataFrame({
    "Inspection minutes": [3, 9, 18],
    "First attempt": [True, False, True],
})

report = sv.compare(
    [a, "Fictional Batch A"],
    [b, "Fictional Batch B"],
    target_feat="First attempt",
    feat_cfg=sv.FeatureConfig(force_num="Inspection minutes"),
    pairwise_analysis="off",
)
report.show_html(
    str(Path("comparison.html")),
    open_browser=False,
    layout="vertical",
    scale=1.0,
)

In the executed Sweetviz 2.3.2 example, automatic inference treated the small inspection-time sample as categorical. The explicit force_num setting makes the intended numeric analysis visible; the generated summary then reports means of 5.00 and 10.00 minutes.

The explicit output path identifies the delivery file. Setting open_browser=False writes it without asking the script to launch a browser. The selected package's show_html implementation writes the HTML before the optional browser step. The official output guide describes vertical layout as a compact arrangement with details expanded by clicking a feature.

Vertical layout is a layout choice, not evidence that every phone can read the report. Open the generated file at the recipient's likely width and inspect the detail area as well as the initial summary. Shrinking an entire report can leave numbers technically present but too small to read. Preserve the original export when making a separate reading copy.

Check the two denominators before interpreting the colors

First check that the report names Batch A and Batch B in the intended order and shows four and three source rows. Then inspect the boolean target and recover its displayed proportions from two successes in each batch. Finally open the numeric feature and compare its mean with the independent calculations above.

If a result disagrees, return to the supplied rows, column types, and sample assignment. Do not edit the HTML number until it matches an expectation. That would disconnect the displayed result from the generated analysis. For real inputs, state any row exclusions before comparing the resulting totals.

The accompanying reading page shows the same seven fictional records and the independent denominator calculations. It is an authored companion, not a modified Sweetviz layout. The untouched native export remains separately downloadable.

Keep the generator with the exported report. It contains the fictional source rows, names, units, and analysis settings needed to reproduce this exercise. Changing the Python input requires generating and checking a new report. An exported HTML file is the result of that run; opening it does not rerun the Python calculation.

Maintained source · Untouched native output

Keep reading