export_xlsx

export_xlsx(*tables, path=None, sheet_names=None, **named_tables)

Export several tables to one Excel workbook, a tab each.

A quick way to drop a handful of summaries into a single .xlsx, one per worksheet, e.g. export_xlsx(calc_percentage(d, "a"), calc_percentage(d, "b"), path="out.xlsx"). Each argument becomes one worksheet: unnamed tables first, in order, then named ones. Tab names are taken from the argument names you give (gender=...), otherwise from each table’s variable column or first column, otherwise Sheet1, Sheet2, …; they are then cleaned to valid, unique Excel names (at most 31 characters, with [ ] : * ? / \ replaced).

Parameters

Name Type Description Default
*tables pandas.DataFrame Data frames to write, one per tab. ()
path str Output .xlsx path. None (default) writes tables.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
sheet_names list of str Tab names (overrides argument names). None
**named_tables pandas.DataFrame Data frames to write under the argument’s name. {}

Returns

Name Type Description
str path.

See Also

save_data

Examples

>>> import tempfile, os
>>> tmp = os.path.join(tempfile.mkdtemp(), "tables.xlsx")
>>> export_xlsx(
...     calc_percentage(podracing_survey, "demo_job"),
...     gender=calc_percentage(podracing_survey, "demo_gender"),
...     path=tmp,
... )
>>> os.path.exists(tmp)