vivainsights.create_line

Visualize the average of a metric by sub-population over time as a line chart.

Returns a line plot showing the average of a selected metric by default. Additional options available to return a summary table.

vivainsights.create_line.create_line_calc(data, metric, hrvar, mingroup=5)[source]

Compute weekly averages of a metric by HR group.

Used internally by create_line.

Parameters:
  • data (pandas.DataFrame) – Person query data.

  • metric (str) – Name of the metric column.

  • hrvar (str) – Name of the organizational attribute for grouping.

  • mingroup (int, default 5) – Minimum group size.

Returns:

Weekly mean of the metric per group with a count column.

Return type:

pandas.DataFrame

vivainsights.create_line.create_line_viz(data, metric, hrvar, mingroup=5, figsize=None)[source]

Create a line chart of a metric over time by HR group.

When the grouping variable has four or fewer unique values a single multi-line chart is produced; otherwise a faceted grid is used. Called internally by create_line when return_type="plot".

Parameters:
  • data (pandas.DataFrame) – Person query data.

  • metric (str) – Name of the metric column.

  • hrvar (str) – Name of the organizational attribute for grouping.

  • mingroup (int, default 5) – Minimum group size.

  • figsize (tuple or None, default None) – Figure size (width, height) in inches.

Returns:

The line chart.

Return type:

matplotlib.figure.Figure or seaborn.FacetGrid

vivainsights.create_line.create_line(data, metric, hrvar, mingroup=5, return_type='plot', figsize=None)[source]

Visualize a metric over time as a line chart.

Provides a week-by-week view of a selected metric, grouped by an HR variable. Returns a line chart or a summary table depending on return_type.

Parameters:
  • data (pandas.DataFrame) – Person query data.

  • metric (str) – Name of the metric to analyse.

  • hrvar (str) – Name of the organizational attribute for grouping.

  • mingroup (int, default 5) – Minimum group size.

  • return_type (str, default "plot") – "plot" for a matplotlib figure, "table" for a DataFrame.

  • figsize (tuple or None, default None) – Figure size (width, height) in inches. Defaults to (8, 6).

Returns:

A line chart or a summary table.

Return type:

matplotlib.figure.Figure, seaborn.FacetGrid, or pandas.DataFrame

Examples

Return a line chart (default):

>>> import vivainsights as vi
>>> pq_data = vi.load_pq_data()
>>> vi.create_line(pq_data, metric="Collaboration_hours", hrvar="LevelDesignation")

Return a summary table of weekly averages:

>>> vi.create_line(pq_data, metric="Collaboration_hours", hrvar="LevelDesignation", return_type="table")

Customize figure size:

>>> vi.create_line(
...     pq_data,
...     metric="Collaboration_hours",
...     hrvar="Organization",
...     figsize=(12, 6),
... )