niimpy.analysis.rhythms module

niimpy.analysis.rhythms.compute_rhythms(df: DataFrame, timebin: str, cols: list, groupby_cols: list, period: int, freq: str, group: str | None = None) DataFrame[source]

Returns a pandas DataFrame containing rhythm computations for the input data based on specified frequency.

Parameters:
dfpandas.DataFrame

Input dataframe with a Timestamp index and ‘user’ column.

timebinstr

Time bin for grouping, using pandas frequency string (e.g., ‘1h’, ‘2h’, ‘4h’, ‘6h’).

colslist

List of columns to compute the count distribution for.

groupby_colslist

Columns by which to group the data.

periodint

Duration in hours for which rhythm is computed. E.g., 8 weeks would be 8*7*24 hours.

freqstr

Sampling frequency, either ‘daily’ or ‘weekly’.

Returns:
rhythmspandas.DataFrame

Dataframe detailing call count distribution rhythms.

Raises:
ValueError:

If provided frequency is incorrect or a specified column isn’t in the dataframe.

niimpy.analysis.rhythms.rhythm(df, period='4W', freq='1W', bin='1D', cols=[], groupby_cols=None)[source]

Compute rhythms from the input data.

  • Resample data to the given frequency.

  • Aggregate data to the specified period.

  • Compute the distribution over the frequency for the specified columns.

Parameters:
dfpandas.DataFrame

Input dataframe with a Timestamp index.

periodstr

Period for which to compute the rhythm. Default is ‘M’ for monthly.

freqstr

Frequency for the rhythm. Default is ‘W’ for weekly.

binstr

Time bin for the rhythm computation. Defaults to ‘D’ for daily.

colslist

List of columns to compute the count distribution for.

groupby_colslist

Columns by which to group the data. Defaults to user and device

Returns:
rhythmspandas.DataFrame

Dataframe detailing rhythms.