timeseries_shaper.filter.custom_filter
1from ..base import Base 2import pandas as pd 3 4class CustomFilter(Base): 5 @classmethod 6 def filter_custom_conditions(cls, dataframe: pd.DataFrame, conditions: str) -> pd.DataFrame: 7 """ 8 Filters the DataFrame based on a set of user-defined conditions passed as a string. 9 10 This method allows for flexible data filtering by evaluating a condition or multiple conditions 11 specified in the 'conditions' parameter. The conditions must be provided as a string 12 that can be interpreted by pandas' DataFrame.query() method. 13 14 Args: 15 - dataframe (pd.DataFrame): The DataFrame to apply the filter on. 16 - conditions (str): A string representing the conditions to filter the DataFrame. 17 The string should be formatted according to pandas query syntax. 18 19 Returns: 20 - pd.DataFrame: A DataFrame containing only the rows that meet the specified conditions. 21 22 Example: 23 -------- 24 # Given a DataFrame 'df' containing columns 'age' and 'score': 25 >>> filtered_data = CustomFilter.filter_custom_conditions(df, "age > 30 and score > 80") 26 >>> print(filtered_data) 27 28 Note: 29 - Ensure that the column names and values used in conditions match those in the DataFrame. 30 - Complex expressions and functions available in pandas query syntax can also be used. 31 """ 32 return dataframe.query(conditions)
class
CustomFilter(timeseries_shaper.base.Base):
5class CustomFilter(Base): 6 @classmethod 7 def filter_custom_conditions(cls, dataframe: pd.DataFrame, conditions: str) -> pd.DataFrame: 8 """ 9 Filters the DataFrame based on a set of user-defined conditions passed as a string. 10 11 This method allows for flexible data filtering by evaluating a condition or multiple conditions 12 specified in the 'conditions' parameter. The conditions must be provided as a string 13 that can be interpreted by pandas' DataFrame.query() method. 14 15 Args: 16 - dataframe (pd.DataFrame): The DataFrame to apply the filter on. 17 - conditions (str): A string representing the conditions to filter the DataFrame. 18 The string should be formatted according to pandas query syntax. 19 20 Returns: 21 - pd.DataFrame: A DataFrame containing only the rows that meet the specified conditions. 22 23 Example: 24 -------- 25 # Given a DataFrame 'df' containing columns 'age' and 'score': 26 >>> filtered_data = CustomFilter.filter_custom_conditions(df, "age > 30 and score > 80") 27 >>> print(filtered_data) 28 29 Note: 30 - Ensure that the column names and values used in conditions match those in the DataFrame. 31 - Complex expressions and functions available in pandas query syntax can also be used. 32 """ 33 return dataframe.query(conditions)
@classmethod
def
filter_custom_conditions( cls, dataframe: pandas.core.frame.DataFrame, conditions: str) -> pandas.core.frame.DataFrame:
6 @classmethod 7 def filter_custom_conditions(cls, dataframe: pd.DataFrame, conditions: str) -> pd.DataFrame: 8 """ 9 Filters the DataFrame based on a set of user-defined conditions passed as a string. 10 11 This method allows for flexible data filtering by evaluating a condition or multiple conditions 12 specified in the 'conditions' parameter. The conditions must be provided as a string 13 that can be interpreted by pandas' DataFrame.query() method. 14 15 Args: 16 - dataframe (pd.DataFrame): The DataFrame to apply the filter on. 17 - conditions (str): A string representing the conditions to filter the DataFrame. 18 The string should be formatted according to pandas query syntax. 19 20 Returns: 21 - pd.DataFrame: A DataFrame containing only the rows that meet the specified conditions. 22 23 Example: 24 -------- 25 # Given a DataFrame 'df' containing columns 'age' and 'score': 26 >>> filtered_data = CustomFilter.filter_custom_conditions(df, "age > 30 and score > 80") 27 >>> print(filtered_data) 28 29 Note: 30 - Ensure that the column names and values used in conditions match those in the DataFrame. 31 - Complex expressions and functions available in pandas query syntax can also be used. 32 """ 33 return dataframe.query(conditions)
Filters the DataFrame based on a set of user-defined conditions passed as a string.
This method allows for flexible data filtering by evaluating a condition or multiple conditions specified in the 'conditions' parameter. The conditions must be provided as a string that can be interpreted by pandas' DataFrame.query() method.
Args:
- dataframe (pd.DataFrame): The DataFrame to apply the filter on.
- conditions (str): A string representing the conditions to filter the DataFrame. The string should be formatted according to pandas query syntax.
Returns:
- pd.DataFrame: A DataFrame containing only the rows that meet the specified conditions.
Example:
Given a DataFrame 'df' containing columns 'age' and 'score':
>>> filtered_data = CustomFilter.filter_custom_conditions(df, "age > 30 and score > 80")
>>> print(filtered_data)
Note:
- Ensure that the column names and values used in conditions match those in the DataFrame.
- Complex expressions and functions available in pandas query syntax can also be used.
Inherited Members
- timeseries_shaper.base.Base
- Base
- dataframe
- get_dataframe