mlprimitives.adapters.pandas module

mlprimitives.adapters.pandas.resample(df, rule, on=None, groupby=(), aggregation='mean', reset_index=True, time_index=None)[source]

pd.DataFrame.resample adapter.

Call the df.resample method on the given time_index and afterwards call the indicated aggregation.

Optionally group the dataframe by the indicated columns before performing the resampling.

If groupby option is used, the result is a multi-index datagrame.

Parameters
  • df (pandas.DataFrame) – DataFrame to resample.

  • rule (str or int) – The offset string or object representing target conversion or an integer value that will be interpreted as the number of seconds.

  • on (str or None) – Name of the column to use as the time index. If None is given, the DataFrame index is used.

  • groupby (list) – Optional list of columns to group by.

  • aggregation (callable or str) – Function or name of the function to use for the aggregation. If a name is given, it can either be one of the standard pandas aggregation functions or the fully qualified name of a python function that will be imported and used.

  • reset_index (bool) – Whether to reset the index after aggregating

  • time_index (str or None) – Deprecated: This has been renamed to on. Name of the column to use as the time index. If None is given, the DataFrame is index is used.

Returns

resampled dataframe

Return type

pandas.Dataframe

mlprimitives.adapters.pandas.unstack(df, level=-1, reset_index=True)[source]

pd.DataFrame.unstack adapter.

Call the df.unstack method using the indicated level and afterwards join the column names using an underscore.

Parameters
  • df (pandas.DataFrame) – DataFrame to unstack.

  • level (str, int or list) – Level(s) of index to unstack, can pass level name

  • reset_index (bool) – Whether to reset the index after unstacking

Returns

unstacked dataframe

Return type

pandas.Dataframe