data[‘Gender’].fillna(data[‘Gender’].mode().iloc[0],inplace=True)
data[‘Married’].fillna(data[‘Married’].mode().iloc[0],inplace=True)
data[‘Self_Employed’].fillna(data[‘Self_Employed’].mode().iloc[0],inplace=True)
data[‘Gender’].fillna(data[‘Gender’].iloc[0])
impute_grps = data.pivot_table(values=[“LoanAmount”],index=[“Gender”,“Married”,“Self_Employed”],aggfunc=np.mean)
for i,row in data.loc[data[‘LoanAmount’].isnull(),:].iterrows():
ind = tuple ([row[‘Gender’],row[‘Married’],row[‘Self_Employed’]])
data.loc[i,‘LoanAmount’] = impute_grps.loc[ind].values[0]
data_merged = data.merge(right=prop_rates,how=‘inner’,left_on=‘Property_Area’,right_index=True,sort=False)
data_merged.pivot_table(values=‘Credit_History’,index=[‘Property_Area’,‘rates’],aggfunc=len)
cut_points = [90,140,190]
break_points = [data[‘LoanAmount’].min()] + cut_points + [data[‘LoanAmount’].max()]
print(break_points)
labels = [“low”,“medium”,“high”,“very_high”]
data[‘LoanAmount_Bin’] = pd.cut(data[‘LoanAmount’],bins=break_points,right=False,labels=labels,include_lowest=True)
pd.value_counts(data[‘LoanAmount_Bin’],sort=False)
data[‘Loan_Status_Coded’] = data[“Loan_Status”].replace({‘N’:0,‘Y’:1})
data[‘Loan_Status_Coded’].value_counts()
dummies = pd.get_dummies(data[‘LoanAmount_Bin’],prefix=‘LoanAmount’)
data_onehot = pd.concat([data,dummies],axis=1)
data_onehot.head(10)