timeseries_shaper.filter.string_filter

 1import pandas as pd
 2from ..base import Base
 3
 4class StringFilter(Base):
 5    """
 6    A class for filtering operations on string columns within a pandas DataFrame.
 7    
 8    Provides class methods for operations on string columns.
 9    """
10
11    @classmethod
12    def filter_na_value_string(cls, dataframe: pd.DataFrame, column_name: str = 'value_string') -> pd.DataFrame:
13        """Filters out rows where the specified string column is NA."""
14        return dataframe[dataframe[column_name].notna()]
15
16    @classmethod
17    def filter_value_string_match(cls, dataframe: pd.DataFrame, string_value: str, column_name: str = 'value_string') -> pd.DataFrame:
18        """Filters rows where the specified string column matches the provided string."""
19        return dataframe[dataframe[column_name] == string_value]
20
21    @classmethod
22    def filter_value_string_not_match(cls, dataframe: pd.DataFrame, string_value: str, column_name: str = 'value_string') -> pd.DataFrame:
23        """Filters rows where the specified string column does not match the provided string."""
24        return dataframe[dataframe[column_name] != string_value]
25
26    @classmethod
27    def filter_string_contains(cls, dataframe: pd.DataFrame, substring: str, column_name: str = 'value_string') -> pd.DataFrame:
28        """Filters rows where the specified string column contains the provided substring."""
29        return dataframe[dataframe[column_name].str.contains(substring, na=False)]
30
31    @classmethod
32    def regex_clean_value_string(cls, dataframe: pd.DataFrame, column_name: str = 'value_string', regex_pattern: str = r'(\d+)\s*([a-zA-Z]*)', replacement: str = '', regex: bool = True) -> pd.DataFrame:
33        """Applies a regex pattern to clean the specified string column."""
34        dataframe[column_name] = dataframe[column_name].str.replace(regex_pattern, replacement, regex=regex)
35        return dataframe
36
37    @classmethod
38    def detect_changes_in_string(cls, dataframe: pd.DataFrame, column_name: str = 'value_string') -> pd.DataFrame:
39        """Detects changes from row to row in the specified string column."""
40        changes_detected = dataframe[column_name].ne(dataframe[column_name].shift())
41        result = dataframe[changes_detected]
42        if result.empty:
43            print(f"No changes detected in the '{column_name}' column between consecutive rows.")
44        return result
class StringFilter(timeseries_shaper.base.Base):
 5class StringFilter(Base):
 6    """
 7    A class for filtering operations on string columns within a pandas DataFrame.
 8    
 9    Provides class methods for operations on string columns.
10    """
11
12    @classmethod
13    def filter_na_value_string(cls, dataframe: pd.DataFrame, column_name: str = 'value_string') -> pd.DataFrame:
14        """Filters out rows where the specified string column is NA."""
15        return dataframe[dataframe[column_name].notna()]
16
17    @classmethod
18    def filter_value_string_match(cls, dataframe: pd.DataFrame, string_value: str, column_name: str = 'value_string') -> pd.DataFrame:
19        """Filters rows where the specified string column matches the provided string."""
20        return dataframe[dataframe[column_name] == string_value]
21
22    @classmethod
23    def filter_value_string_not_match(cls, dataframe: pd.DataFrame, string_value: str, column_name: str = 'value_string') -> pd.DataFrame:
24        """Filters rows where the specified string column does not match the provided string."""
25        return dataframe[dataframe[column_name] != string_value]
26
27    @classmethod
28    def filter_string_contains(cls, dataframe: pd.DataFrame, substring: str, column_name: str = 'value_string') -> pd.DataFrame:
29        """Filters rows where the specified string column contains the provided substring."""
30        return dataframe[dataframe[column_name].str.contains(substring, na=False)]
31
32    @classmethod
33    def regex_clean_value_string(cls, dataframe: pd.DataFrame, column_name: str = 'value_string', regex_pattern: str = r'(\d+)\s*([a-zA-Z]*)', replacement: str = '', regex: bool = True) -> pd.DataFrame:
34        """Applies a regex pattern to clean the specified string column."""
35        dataframe[column_name] = dataframe[column_name].str.replace(regex_pattern, replacement, regex=regex)
36        return dataframe
37
38    @classmethod
39    def detect_changes_in_string(cls, dataframe: pd.DataFrame, column_name: str = 'value_string') -> pd.DataFrame:
40        """Detects changes from row to row in the specified string column."""
41        changes_detected = dataframe[column_name].ne(dataframe[column_name].shift())
42        result = dataframe[changes_detected]
43        if result.empty:
44            print(f"No changes detected in the '{column_name}' column between consecutive rows.")
45        return result

A class for filtering operations on string columns within a pandas DataFrame.

Provides class methods for operations on string columns.

@classmethod
def filter_na_value_string( cls, dataframe: pandas.core.frame.DataFrame, column_name: str = 'value_string') -> pandas.core.frame.DataFrame:
12    @classmethod
13    def filter_na_value_string(cls, dataframe: pd.DataFrame, column_name: str = 'value_string') -> pd.DataFrame:
14        """Filters out rows where the specified string column is NA."""
15        return dataframe[dataframe[column_name].notna()]

Filters out rows where the specified string column is NA.

@classmethod
def filter_value_string_match( cls, dataframe: pandas.core.frame.DataFrame, string_value: str, column_name: str = 'value_string') -> pandas.core.frame.DataFrame:
17    @classmethod
18    def filter_value_string_match(cls, dataframe: pd.DataFrame, string_value: str, column_name: str = 'value_string') -> pd.DataFrame:
19        """Filters rows where the specified string column matches the provided string."""
20        return dataframe[dataframe[column_name] == string_value]

Filters rows where the specified string column matches the provided string.

@classmethod
def filter_value_string_not_match( cls, dataframe: pandas.core.frame.DataFrame, string_value: str, column_name: str = 'value_string') -> pandas.core.frame.DataFrame:
22    @classmethod
23    def filter_value_string_not_match(cls, dataframe: pd.DataFrame, string_value: str, column_name: str = 'value_string') -> pd.DataFrame:
24        """Filters rows where the specified string column does not match the provided string."""
25        return dataframe[dataframe[column_name] != string_value]

Filters rows where the specified string column does not match the provided string.

@classmethod
def filter_string_contains( cls, dataframe: pandas.core.frame.DataFrame, substring: str, column_name: str = 'value_string') -> pandas.core.frame.DataFrame:
27    @classmethod
28    def filter_string_contains(cls, dataframe: pd.DataFrame, substring: str, column_name: str = 'value_string') -> pd.DataFrame:
29        """Filters rows where the specified string column contains the provided substring."""
30        return dataframe[dataframe[column_name].str.contains(substring, na=False)]

Filters rows where the specified string column contains the provided substring.

@classmethod
def regex_clean_value_string( cls, dataframe: pandas.core.frame.DataFrame, column_name: str = 'value_string', regex_pattern: str = '(\\d+)\\s*([a-zA-Z]*)', replacement: str = '', regex: bool = True) -> pandas.core.frame.DataFrame:
32    @classmethod
33    def regex_clean_value_string(cls, dataframe: pd.DataFrame, column_name: str = 'value_string', regex_pattern: str = r'(\d+)\s*([a-zA-Z]*)', replacement: str = '', regex: bool = True) -> pd.DataFrame:
34        """Applies a regex pattern to clean the specified string column."""
35        dataframe[column_name] = dataframe[column_name].str.replace(regex_pattern, replacement, regex=regex)
36        return dataframe

Applies a regex pattern to clean the specified string column.

@classmethod
def detect_changes_in_string( cls, dataframe: pandas.core.frame.DataFrame, column_name: str = 'value_string') -> pandas.core.frame.DataFrame:
38    @classmethod
39    def detect_changes_in_string(cls, dataframe: pd.DataFrame, column_name: str = 'value_string') -> pd.DataFrame:
40        """Detects changes from row to row in the specified string column."""
41        changes_detected = dataframe[column_name].ne(dataframe[column_name].shift())
42        result = dataframe[changes_detected]
43        if result.empty:
44            print(f"No changes detected in the '{column_name}' column between consecutive rows.")
45        return result

Detects changes from row to row in the specified string column.

Inherited Members
timeseries_shaper.base.Base
Base
dataframe
get_dataframe