def apply_function(df, function, row_or_col=None, rows_or_cols=None):
    """
    
    :param df: pd.DataFrame; DataFrame to perform function on
    :param function: function(); The function to be applied
    :param row_or_col: str; Choose if row or col is to be performed on
    :param rows_or_cols: list(); List of the rows or columns to apply the function to
    :return: df; pd.DataFrame: DataFrame with the function applied to the desired rows or columns
    """
    if row_or_col == "col".lower():
        df[rows_or_cols] = df[rows_or_cols].apply(function)
        return df
    elif row_or_col == "row".lower():
        df.loc[rows_or_cols] = df.loc[rows_or_cols].apply(function)
        return df
    else:
        return "Invalid: Select row or col"