def pendiente(list_range, lista):
return np.polyfit(
list_range,
lista,
deg=1
)[0]
%%time
sklearn_test['pendiente'] = sklearn_test[[col for col in sklearn_test.columns if 'tasa_test' in col]].apply(
lambda _: pendiente(list_range, list(_)),
axis=1
)
grupos_score = ['Q4', 'Q3', 'Q2', 'Q1'][::-1]
cortes_deciles = [0, 0.25, 0.5, 0.75, 1]
sklearn_test['grupo_pendiente'] = list(
pd.qcut(sklearn_test['pendiente'], cortes_deciles, labels=grupos_score)
)
sklearn_test.groupby(by=['grupo_pendiente']).agg({
'flg_desembolso': ['count', 'mean'], 'pendiente': ['max', 'min', 'mean', 'median']
})
Add a code snippet to your website: www.paste.org