save_data
save_data(data, path=None, na='', **kwargs)Quick-save a table to CSV, TSV or XLSX.
A pipe-friendly one-liner for dropping a summary table to disk. The format is taken from the file extension. For .xlsx, pass a single data frame for one sheet, or a dict of data frames to write one sheet per element. Returns its input so it can sit mid-pipeline. To send several separate calls to their own tabs in one line, see export_xlsx().
CSV and TSV are written the way R’s readr writes them: no row index, missing values as na, whole numbers without a decimal point.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | pandas.DataFrame or dict of DataFrame | A data frame, or (for .xlsx) a dict of them keyed by sheet name. | required |
| path | str | Output path; the extension sets the format (.csv, .tsv, .xlsx). None (default) writes data.csv. A bare file name lands in ezrsurvey-outputs/ (created on demand); a path naming a directory (“./x.csv”, “charts/x.csv”, anything absolute) is used exactly as given. See the output_dir option. |
None |
| na | str | String to write for missing values. Default ““. | '' |
| **kwargs | Passed to DataFrame.to_csv(). |
{} |
Returns
| Name | Type | Description |
|---|---|---|
| pandas.DataFrame or dict | data. |
See Also
save_plot, save_output, export_xlsx
Examples
>>> import tempfile, os
>>> tab = calc_percentage(podracing_survey, "demo_gender")
>>> tmp = os.path.join(tempfile.mkdtemp(), "table.csv")
>>> save_data(tab, tmp)
>>> os.path.exists(tmp)