featuretools.primitives.RollingCount¶
- class featuretools.primitives.RollingCount(window_length=3, gap=0, min_periods=0)[source]¶
Determines a rolling count of events over a given window.
- Description:
Given a list of datetimes, return a rolling count starting at the row gap rows away from the current row and looking backward over the specified time window (by window_length and gap).
Input datetimes should be monotonic.
- Parameters
window_length (int) – The number of rows to be included in each frame. For data with a uniform sampling frequency, for example of one day, the window_length will correspond to a period of time, in this case, 7 days for a window_length of 7.
gap (int, optional) – The number of rows backward from the target instance before the window of usable data begins. Defaults to 0, which will include the target instance in the window.
min_periods (int, optional) – Minimum number of observations required for a window to have a value. Can only be as large as window_length. Defaults to 1.
Examples
>>> import pandas as pd >>> rolling_count = RollingCount(window_length=3) >>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5) >>> rolling_count(times).tolist() [1.0, 2.0, 3.0, 3.0, 3.0]
We can also control the gap before the rolling calculation.
>>> import pandas as pd >>> rolling_count = RollingCount(window_length=3, gap=1) >>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5) >>> rolling_count(times).tolist() [nan, 1.0, 2.0, 3.0, 3.0]
We can also control the minimum number of periods required for the rolling calculation.
>>> import pandas as pd >>> rolling_count = RollingCount(window_length=3, min_periods=3) >>> times = pd.date_range(start='2019-01-01', freq='1min', periods=5) >>> rolling_count(times).tolist() [nan, nan, 3.0, 3.0, 3.0]
Methods
__init__([window_length, gap, min_periods])generate_name(base_feature_names)generate_names(base_feature_names)get_args_string()get_arguments()get_description(input_column_descriptions[, ...])get_filepath(filename)get_function()Attributes
base_ofbase_of_excludecommutativecompatibilityAdditional compatible libraries
default_valueDefault value this feature returns if no data found.
description_templateinput_typeswoodwork.ColumnSchema types of inputs
max_stack_depthnameName of the primitive
number_output_featuresNumber of columns in feature matrix associated with this feature
return_typeColumnSchema type of return
uses_calc_timeuses_full_dataframe