vivainsights.totals_col

Add a totals column with a specified value to a DataFrame.

vivainsights.totals_col.totals_col(data, total_value='Total')[source]

Add a new column with a specified total value to a DataFrame.

Parameters:
  • data (pandas.DataFrame) – Input DataFrame.

  • total_value (str, optional) – Name and fill value for the new column. Defaults to "Total".

Returns:

The input DataFrame with the new column appended.

Return type:

pandas.DataFrame

Raises:

ValueError – If a column named total_value already exists.

Examples

Add a default “Total” column:

>>> import vivainsights as vi
>>> pq_data = vi.load_pq_data()
>>> vi.totals_col(pq_data, total_value="Total")

Use a custom label:

>>> vi.totals_col(pq_data, total_value="AllEmployees")