helpers/utils.py
def create_mapping(self, df: pd.DataFrame, keycol: str, valuecol: str, feature_name: str = None) -> None:
        """
            Creates mapping between the numerical encoding of the selected categorical variable and the
            full names of its categories

            Args
            ----------
            df: pd.DataFrame
                        input dataframe containing the categorical variables

            keycol: str
                        name of the column in df that contains the numerical encoding

            valuecol: str
                        name of the column in df that contains the full name of the category

            feature_name: str (Optional, default None)
                        key to use for saving the created mapping to master mappings 
                        (i.e. self.mappings[feature_name] = created_mapping)

            Returns
            ----------
            None            
        """
        # Drop duplicate rows based on both keycol and valuecol
        df_unique = df[[keycol, valuecol]].drop_duplicates()
        
        # Check for duplicate keys and values
        assert len(df_unique[keycol].unique()) == len(df_unique), "Duplicate keys detected"
        assert len(df_unique[valuecol].unique()) == len(df_unique), "Duplicate values detected"
        
        # Create dictionary based on key-value pairs
        mapping = dict(zip(df_unique[keycol].values, df_unique[valuecol].values))
        
        # Sort the dictionary based on keys
        sorted_mapping = dict(sorted(mapping.items()))
        
        feature_name = feature_name if feature_name else keycol
        assert feature_name not in self.mappings, f"The key {feature_name} is already in mappings"
        self.mappings[feature_name] = sorted_mapping
        
        # Drop the value column
        df.drop(columns=[valuecol], inplace=True)

            Creates mapping between the numerical encoding of the selected categorical variable and the
            full names of its categories

            Args
            ----------
            df: pd.DataFrame
                        input dataframe containing the categorical variables

            keycol: str
                        name of the column in df that contains the numerical encoding

            valuecol: str
                        name of the column in df that contains the full name of the category

            feature_name: str (Optional, default None)
                        key to use for saving the created mapping to master mappings 
                        (i.e. self.mappings[feature_name] = created_mapping)

            Returns
            ----------
            None            
        
Creates mapping between the numerical encoding of the selected categorical variable and the
full names of its categories

Args

pd.DataFrame
input dataframe containing the categorical variables

str
name of the column in df that contains the numerical encoding

str
name of the column in df that contains the full name of the category

str (Optional, default None)
key to use for saving the created mapping to master mappings

Returns

None
Creates mapping between the numerical encoding of the selected categorical variable and the full names of its categories Args pd . DataFrame input dataframe containing the categorical variables str name of the column in df that contains the numerical encoding str name of the column in df that contains the full name of the category str ( Optional default None ) key to use for saving the created mapping to master mappings Returns None
def create_mapping(self, df: pd.DataFrame, keycol: str, valuecol: str, feature_name: str = None) -> None:
        df_unique = df[[keycol, valuecol]].drop_duplicates()
        assert len(df_unique[keycol].unique()) == len(df_unique), "Duplicate keys detected"
        assert len(df_unique[valuecol].unique()) == len(df_unique), "Duplicate values detected"
        mapping = dict(zip(df_unique[keycol].values, df_unique[valuecol].values))
        sorted_mapping = dict(sorted(mapping.items()))
        feature_name = feature_name if feature_name else keycol
        assert feature_name not in self.mappings, f"The key {feature_name} is already in mappings"
        self.mappings[feature_name] = sorted_mapping
        df.drop(columns=[valuecol], inplace=True)
def create_mapping ( self , df : pd . DataFrame , keycol : str , valuecol : str , feature_name : str = None ) -> None : df_unique = df [ [ keycol , valuecol ] ] . drop_duplicates ( ) assert len ( df_unique [ keycol ] . unique ( ) ) == len ( df_unique ) , "Duplicate keys detected" assert len ( df_unique [ valuecol ] . unique ( ) ) == len ( df_unique ) , "Duplicate values detected" mapping = dict ( zip ( df_unique [ keycol ] . values , df_unique [ valuecol ] . values ) ) sorted_mapping = dict ( sorted ( mapping . items ( ) ) ) feature_name = feature_name if feature_name else keycol assert feature_name not in self . mappings , f"The key {feature_name} is already in mappings" self . mappings [ feature_name ] = sorted_mapping df . drop ( columns = [ valuecol ] , inplace = True )
Creates mapping between the numerical encoding of the selected categorical variable and the
full names of its categories
Creates mapping between the numerical encoding of the selected categorical variable and the full names of its categories
"""
            Creates mapping between the numerical encoding of the selected categorical variable and the
            full names of its categories

            Args
            ----------
            df: pd.DataFrame
                        input dataframe containing the categorical variables

            keycol: str
                        name of the column in df that contains the numerical encoding

            valuecol: str
                        name of the column in df that contains the full name of the category

            feature_name: str (Optional, default None)
                        key to use for saving the created mapping to master mappings 
                        (i.e. self.mappings[feature_name] = created_mapping)

            Returns
            ----------
            None            
        """ # Drop duplicate rows based on both keycol and valuecol # Check for duplicate keys and values # Create dictionary based on key-value pairs # Sort the dictionary based on keys # Drop the value column
self
df
pd.DataFrame
keycol
str
valuecol
str
feature_name
str