featuretools.primitives.SameAsPrevious#

class featuretools.primitives.SameAsPrevious(fill_method='pad', limit=None)[source]#

Determines if a value is equal to the previous value in a list.

Description:

Compares a value in a list to the previous value and returns True if the value is equal to the previous value or False otherwise. The first item in the output will always be False, since there is no previous element for the first element comparison.

Any nan values in the input will be filled using either a forward-fill or backward-fill method, specified by the fill_method argument. The number of consecutive nan values that get filled can be limited with the limit argument. Any nan values left after filling will result in False being returned for any comparison involving the nan value.

Parameters:
  • fill_method (str) – Method for filling gaps in series. Valid

  • backfill (options are) –

  • bfill (backfill /) –

  • pad

  • ffill.

  • ffill (pad /) – fill gap with last valid observation.

  • bfill – fill gap with next valid observation.

  • pad. (Default is) –

  • limit (int) – The max number of consecutive NaN values in a gap that can be filled. Default is None.

Examples

>>> same_as_previous = SameAsPrevious()
>>> same_as_previous([1, 2, 2, 4]).tolist()
[False, False, True, False]

The fill method for nan values can be specified

>>> same_as_previous_fillna = SameAsPrevious(fill_method="bfill")
>>> same_as_previous_fillna([1, None, 2, 4]).tolist()
[False, False, True, False]

The number of nan values that are filled can be limited

>>> same_as_previous_limitfill = SameAsPrevious(limit=2)
>>> same_as_previous_limitfill([1, None, None, None, 2, 3]).tolist()
[False, True, True, False, False, False]
__init__(fill_method='pad', limit=None)[source]#

Methods

__init__([fill_method, limit])

flatten_nested_input_types(input_types)

Flattens nested column schema inputs into a single list.

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_of

base_of_exclude

commutative

compatibility

Additional compatible libraries

default_value

Default value this feature returns if no data found.

description_template

input_types

woodwork.ColumnSchema types of inputs

max_stack_depth

name

Name of the primitive

number_output_features

Number of columns in feature matrix associated with this feature

return_type

ColumnSchema type of return

series_library

stack_on

stack_on_exclude

stack_on_self

uses_calc_time

uses_full_dataframe