AllValueFilterStrategy
- class cocohelper.filters.strategies.strategies.AllValueFilterStrategy[source]
Bases:
ValueFilterStrategy
Filters multi-rows having at least all 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 at least one of the values imposed by the filter are not associated with a certain index idx, all the rows with that index are removed from the dataframe.
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 all the values imposed by the filter.
For example, the dataframe: ``` ———————-
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 AllValueFilterStrategy().apply([0.0, 1.0], ‘B’, df), we will remove the index 0 because column B does not contain one of the imposed values: 1.0. At the same time we will keep indices 1 and 2, because they have both values 0.0 and 1.0 in the column B, so we will have: ``` —————————————–
A B
- index
1 [1.0, 1.0] [0.0, 1.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
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
Method List
apply
(values, column, df)Attributes List
Methods Details
- apply(values, column, df)[source]
- Parameters:
column (str) –
df (DataFrame) –
- Return type:
DataFrame
Attribute Details
- _abc_impl = <_abc._abc_data object>