AnyValueFilterStrategy

class cocohelper.filters.strategies.strategies.AnyValueFilterStrategy[source]

Bases: ValueFilterStrategy

Filters multi-rows having at least one of the requested values.

This strategy can be applied to dataframes that can contain multiple rows sharing the same index.

In that case we consider each index associated with a list of values on each column; and if none of the values associated with a certain index are one of the values imposed by the filter all the rows with that index are removed, otherwise all the rows with that index are kept.

To visualize easier, can consider each unique index as a multi-row containing a list of values on each column. In this case, a multi-row is excluded if the list of values in the selected column does not contain any the values imposed by the filter.

For example, given the dataframe df: ``` ———————-

A B

index

0 0.0 0.0 0 0.0 2.0 1 1.0 0.0 1 1.0 1.0 2 2.0 0.0 2 2.0 1.0 2 2.0 2.0

Is considered a multi-row dataframe like this: ``` —————————————–

A B

index

0 [0.0, 0.0] [0.0, 2.0] 1 [1.0, 1.0] [0.0, 1.0] 2 [2.0, 2.0, 2.0] [0.0, 1.0, 2.0]

If we apply AnyValueFilterStrategy().apply([2.0, 3.0], ‘B’, df), we will remove the index 1 because column B does not contain any of the imposed values (2.0 and 3.0). At the same time we will keep indices 0 and 2, because they have at least one of the values imposed by the filter (2.0 was sufficient in this case).

Resulting multi-row dataframe will be: ``` —————————————–

A B

index

0 [0.0, 0.0] [0.0, 2.0] 2 [2.0, 2.0, 2.0] [0.0, 1.0, 2.0]

Going back to a standard dataframe, this is the result: ``` ———————-

A B

index

0 0.0 0.0 0 0.0 2.0 2 2.0 0.0 2 2.0 1.0 2 2.0 2.0


Method List

apply(values, column, df)

Attributes List

_abc_impl

Methods Details

apply(values, column, df)[source]
Parameters:
  • column (str) –

  • df (DataFrame) –

Return type:

DataFrame

Attribute Details

_abc_impl = <_abc._abc_data object>