Перепиши эту функцию в более красивый вид, при этом чтобы он работал быстрее. Вот код: def features_gini_psi(data, data_psi, target, comb_woe, comb_list_i, date_col,
                        min_feature_gini=0.03,
                        threshold_gini=0.02,
                        threshold_gini_abs=0.07,
                        n_bins_gini_stab=3,
                        perc_diff_gini_stab=0.5,
                        max_psi=0.2,
                        max_psi_oot=0.2,
                        return_df=False
                        ):
    
    vars_woe, woe_models, replace_miss = comb_woe[comb_list_i]
    delete_nan=False

    woe_transform(data, vars_woe, woe_models, replace_miss)
    woe_transform(data_psi, vars_woe, woe_models, replace_miss)

    train_ginis = gini_conf_factors(data, target, vars_woe, return_df=True)
    psi_oot = psi_woefactors(data, data_psi, vars_woe, 'result', psi_gate=max_psi_oot, delete_nan=delete_nan)

    col_names = []
    chunks = np.array_split(np.argsort(data[date_col]), n_bins_gini_stab)

    for num, chunk in enumerate(chunks):
        df_chunk = data[data.index.isin(chunk)]
        tmp_df = gini_conf_factors(df_chunk, target, vars_woe, return_df=True)
        psi_stop_chunk = psi_woefactors(data, df_chunk, vars_woe, 'result', psi_gate=max_psi, delete_nan=delete_nan)
        psi_stop_chunk.columns = ['Фактор', f'PSI_{str(num)}', f'PSI_{str(num)}_gate_{int(max_psi*100)}%']
        
        del df_chunk
        gc.collect()

        tmp_df.rename(columns={"Gini": 'Gini_'+str(num), }, inplace=True)
        col_names.append('Gini_'+str(num))
        if num == 0:  base_df = tmp_df.copy().merge(psi_stop_chunk, how='left')
        else:         base_df = base_df.merge(tmp_df, on='Фактор', how='left').merge(psi_stop_chunk, how='left')

    base_df = base_df.merge(train_ginis, how='left').merge(psi_oot, how='left')

    cols_all = base_df.columns
    g_cols = cols_all[cols_all.str.contains('Gini')]
    p_cols = cols_all[cols_all.str.contains('PSI')]
    p_gate_cols = cols_all[cols_all.str.contains('gate_')]


    base_df['Gini_min'] = base_df[g_cols].min(axis=1)
    base_df['Gini_delta_min'] = base_df['Gini'] - base_df['Gini_min']
    new_cols = [cols_all[0]] + list(g_cols) + ['Gini_min', 'Gini_delta_min'] + list(p_cols)
    base_df = base_df[new_cols]
    base_df.sort_values('Gini', ascending=False, inplace=True)

    name_col_g = f'min_feature_gini_{int(min_feature_gini*100)}%'
    name_col_g1 = f'threshold_gini_{int(threshold_gini*100)}%'
    name_col_g2 = f'absolute_delta_gini_{int(threshold_gini_abs*100)}p.p.'
    name_col_g3 = f'percent_delta_gini_{int(perc_diff_gini_stab*100)}%'
    name_col_g23 = f'absolute_{int(threshold_gini_abs*100)}p.p._and_percent_{int(perc_diff_gini_stab*100)}%_delta_gini'
    name_col_g4 = 'gini_stop_list_all'
    name_col_p = f'threshold_psi_stab_{int(max_psi*100)}%'
    name_col_p1 = f'PSI_gate_{int(max_psi_oot*100)}%'
    name_col_p2 = 'psi_stop_list_all'
    name_col_gp = f'gini_and_psi_stop'

    cols_p_stab = [i for i in p_gate_cols if i != name_col_p1]

    base_df[name_col_g] = (base_df['Gini'] < min_feature_gini).astype(int)
    base_df[name_col_g1] = (base_df['Gini_min'] < threshold_gini).astype(int)
    base_df[name_col_g2] = (base_df['Gini_delta_min'] > threshold_gini_abs).astype(int)
    base_df[name_col_g3] = ( (base_df['Gini_delta_min'] / base_df['Gini']) > perc_diff_gini_stab ).astype(int)
    base_df[name_col_g23] = (base_df[[name_col_g2, name_col_g3]].sum(axis=1) == 2).astype(int)
    base_df[name_col_g4] = base_df[[name_col_g, name_col_g1, name_col_g23]].max(axis=1)

    base_df[name_col_p] = base_df[cols_p_stab].max(axis=1)
    base_df[name_col_p2] = base_df[p_gate_cols].max(axis=1)
    base_df[name_col_gp] = base_df[[name_col_g4, name_col_p2]].max(axis=1)

    cols_res = [name_col_g, name_col_g1, name_col_g2, name_col_g3, name_col_g23, name_col_g4,
                name_col_p, name_col_p1, name_col_p2, name_col_gp]
    res_tab_gini_psi = base_df[cols_res].sum().to_frame().T
    res_tab_gini_psi['gini_mean_top50'] = (base_df['Gini'].head(50).mean() * 100).round(1)
    res_tab_gini_psi['gini_mean_top100'] = (base_df['Gini'].head(100).mean() * 100).round(1)
    res_tab_gini_psi.index = [comb_list_i]

    gini_psi_stop_list = base_df['Фактор'][base_df[name_col_gp] == 1].tolist()
    if return_df:
        return base_df, res_tab_gini_psi, gini_psi_stop_list
    else:
        return res_tab_gini_psi, gini_psi_stop_list