Replacing The Weight-of-evidence (woe) With Its Corresponding Value
I have variable called x whose minimum value is zero and maximum is 2 million. So I cut the value into bins like this code: bins = [0,1,10000,20000,50000,60000,70000,100000,2000000
Solution 1:
I think you need cut
with parameter labels
and for replace misisng value is necessary add cat.add_categories
before replace:
df_input = pd.DataFrame({'X':[0,20,100, 10000, 30000, 1000000]})
b = [-np.inf, 100, 10000, 20000, 50000]
l = ['-0.157688', '-0.083307', '0.381819', '0.364365']
df_input['X_WOE'] = pd.cut(df_input['X'], bins=b, labels=l,right=False)
df_input['X_WOE'] = df_input['X_WOE'].cat.add_categories(['0']).fillna('0')
print (df_input)
X X_WOE
0 0 -0.157688
1 20 -0.157688
2 100 -0.083307
3 10000 0.381819
4 30000 0.364365
5 1000000 0
Post a Comment for "Replacing The Weight-of-evidence (woe) With Its Corresponding Value"