ValueFilter
- class cocohelper.filters.filter.ValueFilter[source]
Bases:
ColumnFilter
Filter the rows having certain values in the chosen column.
Different strategies can be applied to the filter:
- strategies.HAVING_VALUE: this simple strategy keeps the rows whose
value of the selected column is one of the values imposed by the filter.
- strategies.ANY_VALUE: this strategy can be applied to a dataframe with
multiple rows with the same index. In that case we consider the dataframe as a multi-row dataframe (grouped by index). This strategy keeps a multi-row only if at least one of the values in the selected column is in the list of values imposed by the filter
- strategies.ALL_VALUES: this strategy can be applied to a dataframe with
multiple rows with the same index. In that case we consider the dataframe as a multi-row dataframe (grouped by index). A multi-row is discarded if at least one of the values imposed by the filters for the requested column is not in the list of values of the same column in that multi-row.
- Parameters:
values – the values that filtered rows must have.
column – the column on which values are checked.
strategy – the ValueStrategy used by the filter
Method List
_apply
(values, column, df)Applies the filter to the given DataFrame rows.
apply
(df)Apply the filter to the DataFrame
set_strategy
(strategy)Set the filter strategy.
Attributes List
Methods Details
- _apply(values, column, df)[source]
Applies the filter to the given DataFrame rows.
- Parameters:
values – values to filter in the DataFrame.
column (str) – column to filter in the DataFrame.
df (DataFrame) – DataFrame to filter.
- Returns:
The filtered DataFrame.
- Return type:
DataFrame
- apply(df)
Apply the filter to the DataFrame
- Parameters:
df (DataFrame) – DataFrame to filter
- Returns:
The filtered DataFrame.
- Return type:
DataFrame
- set_strategy(strategy)[source]
Set the filter strategy.
- Parameters:
strategy (ValueFilterStrategy) – used for filtering the dataframe when using apply().
- Returns:
None.
Attribute Details
- _abc_impl = <_abc._abc_data object>