use_dataset

use_dataset(data)

Set a default dataset for the session.

Registers a data frame as the session’s default, so the analysis helpers can be called without repeating data every time. Set it once at the top of a script or Quarto document and then omit data (or pass it with DataFrame.pipe()).

With a default set you can drop data entirely and name the column positionally:

  • calc_percentage("demo_gender"): data taken from the default;
  • podracing_survey.pipe(calc_percentage, "demo_gender"): explicit pipe;
  • calc_percentage(other_survey, "demo_gender"): an explicit data frame always wins over the default.

The helpers tell a column from a data frame by looking at the first argument: a data frame is used as the data; anything else (a column name) is taken as the first column and the data comes from the default. Helpers that select several columns (e.g. diagnose(), calc_percentage_batch()) work the same way: diagnose(starts_with("ratings_")) needs no data.

The default applies to the analysis helpers that read a raw survey (calc_percentage(), calc_summary(), calc_nps(), diagnose(), crosstab(), ipm_model(), sample_comments(), …). It does not apply to plot/report helpers that consume an already-summarised table. The setting lives only in the current Python session; clear it with clear_dataset().

Parameters

Name Type Description Default
data pandas.DataFrame A data frame to use as the default. required

Returns

Name Type Description
pandas.DataFrame data, so it can sit in a pipe.

See Also

get_dataset, clear_dataset, has_dataset

Examples

>>> use_dataset(podracing_survey)
>>> calc_percentage("demo_gender")
>>> calc_nps("nps_value")
>>> clear_dataset()