resample#

pymovements.transforms.resample(samples: DataFrame, resampling_rate: float, columns: str | list[str] = 'all', fill_null_strategy: str = 'interpolate_linear', n_components: int | None = None) DataFrame[source]#

Resample a DataFrame to a new sampling rate by timestamps in time column.

The DataFrame is resampled by upsampling or downsampling the data to the new sampling rate. Can also be used to achieve a constant sampling rate for inconsistent data.

Parameters:
  • samples (pl.DataFrame) – The samples DataFrame to resample.

  • resampling_rate (float) – The new sampling rate.

  • columns (str | list[str]) – The columns to apply the fill null strategy. Specify a single column name or a list of column names. If ‘all’ is specified, the fill null strategy is applied to all columns. (default: ‘all’)

  • fill_null_strategy (str) – The strategy to fill null values of the resampled DataFrame. Supported strategies are: ‘forward’, ‘backward’, ‘interpolate_linear’, ‘interpolate_nearest’. Columns must be numeric when using interpolation. (default: ‘interpolate_linear’)

  • n_components (int | None) – Number of components of nested columns in columns. (default: None)

Returns:

The resampled DataFrame.

Return type:

pl.DataFrame

Raises:

ValueError – If the resampling rate is not a divisor of 1000000.

Notes

The following fill null strategies are available:

  • forward: Fill null values with the previous non-null value.

  • backward: Fill null values with the next non-null value.

  • interpolate_linear: Fill null values by linear interpolation.

  • interpolate_nearest: Fill null values by the nearest interpolation.