sebaba/utils.py
def change_vars_to_categorical(df = None, vars_to_change = []):
    """
    Function that changes all non-numeric variables to categorical datatype.
    
    Parameters:
    --------------------------------------------------
        df            : DataFrame
        vars_to_change: list, the variables in the list are converted to categorical datatype.
    
    Returns:
    --------------------------------------------------
        df: DataFrame with categorical datatypes converted
    """
    cat_vars = df.select_dtypes(exclude = "number").columns.to_list()
    
    if len(vars_to_change) > 0:
        cat_vars = vars_to_change
    
    for var in cat_vars:
        df[var] = df[var].astype("category")
        
    return df

    Function that changes all non-numeric variables to categorical datatype.
    
    Parameters:
    --------------------------------------------------
        df            : DataFrame
        vars_to_change: list, the variables in the list are converted to categorical datatype.
    
    Returns:
    --------------------------------------------------
        df: DataFrame with categorical datatypes converted
    
Function that changes all non-numeric variables to categorical datatype.
Function that changes all non - numeric variables to categorical datatype .
def change_vars_to_categorical(df = None, vars_to_change = []):
    cat_vars = df.select_dtypes(exclude = "number").columns.to_list()
    if len(vars_to_change) > 0:
        cat_vars = vars_to_change
    for var in cat_vars:
        df[var] = df[var].astype("category")
    return df
def change_vars_to_categorical ( df = None , vars_to_change = [ ] ) : cat_vars = df . select_dtypes ( exclude = "number" ) . columns . to_list ( ) if len ( vars_to_change ) > 0 : cat_vars = vars_to_change for var in cat_vars : df [ var ] = df [ var ] . astype ( "category" ) return df
Function that changes all non-numeric variables to categorical datatype.
Function that changes all non - numeric variables to categorical datatype .
"""
    Function that changes all non-numeric variables to categorical datatype.
    
    Parameters:
    --------------------------------------------------
        df            : DataFrame
        vars_to_change: list, the variables in the list are converted to categorical datatype.
    
    Returns:
    --------------------------------------------------
        df: DataFrame with categorical datatypes converted
    """
DataFrame with categorical datatypes converted
DataFrame with categorical datatypes converted
df
df
vars_to_change
list, the variables in the list are converted to categorical datatype.
list the variables in the list are converted to categorical datatype .
df            
None