export_summary_xlsx

export_summary_xlsx(
    data=None,
    *columns,
    path=None,
    by=None,
    chart=True,
    sort='none',
    digits=0,
    weights=None,
    width=CHART_WIDTH,
    height=CHART_HEIGHT,
    confirm=None,
)

Export a per-question summary workbook (table + chart per sheet).

Writes one Excel workbook with a worksheet per question, each holding that question’s summary table and its chart. Numeric questions get a calc_summary() table and a histogram; categorical questions get a calc_percentage() table and a plot_bars() chart; check-all-that-apply blocks get a calc_percentage_multi() table (based on the respondents who picked any option) and a bar chart. This is the “hand the client a tabbed workbook” counterpart to the slide/Word builders (report_deck()). Needs the excel extra.

Worksheets are named from each question (cleaned to valid, unique Excel names). The table is written from cell A1; the chart, when included, is embedded a few rows below it. With no columns named, every question in the data is written and identifier / free-text columns are skipped (and named in a message); an interactive session shows that selection and waits for a yes first.

Parameters

Name Type Description Default
data pandas.DataFrame A data frame. If omitted, the session default is used. None
*columns str or selector Variables to summarise, one worksheet per question. If omitted, every question is written. ()
path str Output .xlsx path. None (default) writes summary.xlsx. A bare file name lands in ezrsurvey-outputs/ (created on demand); a path naming a directory (“./x.xlsx”, “charts/x.xlsx”, anything absolute) is used exactly as given. See the output_dir option. None
by str or list of str Grouping column(s) for the tables. The chart is always the ungrouped distribution. None
chart bool Include the chart beneath each table. Default True. True
sort str Level ordering for categorical tables: “none” (default, respecting any registered order), “desc” or “asc”. 'none'
digits int Decimal places for percentages. Default 0. 0
weights (bool, dict or list) Survey weighting, passed to the table and chart helpers. Multi-select blocks are always unweighted. None
width float Chart size in inches. Default 6 x 3.4. CHART_WIDTH
height float Chart size in inches. Default 6 x 3.4. CHART_WIDTH
confirm bool When no variables are named, show which questions were chosen and which were skipped, and wait for a yes before writing. None (default) follows the confirm option. Answering no writes nothing and returns None. None

Returns

Name Type Description
str or None The path written.

See Also

export_xlsx, save_data, report_deck, calc_percentage_batch

Examples

>>> import tempfile, os
>>> path = os.path.join(tempfile.mkdtemp(), "summary.xlsx")
>>> export_summary_xlsx(podracing_survey, "demo_gender", "satis_return", "nps_value", path=path)