diive.keep_vars

diive.keep_vars(data, variables, verbose=False)[source]

Keep only the given variables (columns), preserving their order.

A non-destructive variable subselection (the column analogue of times.keep_daterange): returns a copy containing only variables in the requested order, leaving the input untouched so the caller can keep the full record and revert. Every requested name must exist.

Parameters:
  • data (DataFrame | Series) – A DataFrame, or a Series (returned unchanged if its name is listed).

  • variables (list[str]) – Column names to keep, in the desired order.

  • verbose (bool) – Print how many variables were kept.

Return type:

DataFrame | Series

Returns:

A copy of data restricted to variables.

Raises:

ValueError – If any requested name is not present in the data.