<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv('../input/train_u6lujuX_CVtuZ9i (1).csv')
#df2 = pd.read_csv('D:/datacamp/files/loan predication/test.csv',index_col=['Loan_ID'])
#df=pd.merge(df1,df2)
# printing first five rows
df.head()
df.shape
df.isnull().sum()
list = ['Gender','Married','Education','Self_Employed','Property_Area','Dependents']
def category_var(dataframe,ls):
    for var in ls:
        dataframe[var] =  dataframe[var].astype('category')
    
category_var(df,list)
df.info()
df.isnull().sum()
def fill_missing(df):
    for  col in df:
        #print(df[col].isnull().sum())
        if df[col].dtypes=='category':
            print('hello')

# filling missing values 
category =['Gender','Married','Education','Self_Employed','Property_Area','Dependents','Credit_History']

for var in category:
    df[var].fillna(method='ffill',inplace=True)
    
# filling missing values
def fill_missing(frame,list):
    for var in list:
        if(frame[var].dtypes=='category'):
            frame[var].fillna(method='ffill')
        elif((frame[var]=='int64') or (frame[var]=='float64')):
            frame[var].fillna(np.mean,inplace=True)

#filling missing values
numeric = ['LoanAmount','Loan_Amount_Term']

for var in numeric:
    mean = np.around(np.mean(df[var]),decimals=0)
    df[var].fillna(mean,inplace=True)
df.isnull().sum()
df.boxplot(column='ApplicantIncome',by='Education')
df.columns
df.describe()
#peoples who are not graduated,unmarried  and got a loan a
df[(df['Education']!='Graduate') & (df['Married']=='No') &  (df['Loan_Status']=='Y')]['Self_Employed'].value_counts()
# conclusion-1 -- 82% peoples which are not self emplyoyed and also not graduated and unmarried
df.head()
 data_sorted = df.sort_values(['ApplicantIncome','CoapplicantIncome'], ascending=False)
data_sorted[['ApplicantIncome','CoapplicantIncome']].head(10)
import matplotlib.pyplot as plt
%matplotlib inline
df.boxplot(column="ApplicantIncome",by="Loan_Status")
df.groupby(['Loan_Status','Gender']).sum()
#conclusion3 -- males have high crdit history and more income then females 
df.head()
df['Loan_Status'] = df['Loan_Status'].map({'Y':1,'N':0})
with plt.style.context(('dark_background')):
    pd.crosstab(df['Property_Area'],df['Loan_Status']).plot.bar()
#pd.crosstab(df['Property_Area'],df['Loan_Status'],margins=True).apply(convert_percentage,axis=1)


# HERE 0 DENOTES LOAN-STATUS=='NO'AND 1 DENOTES LOAN-STATUS='YES'
#conclusion--in rural and urban areas loan denied have no signifiacntly differnce 
#and semiurban areas have more peoples of  getting loan
df.head()
income=  df[['ApplicantIncome','CoapplicantIncome','Loan_Status']]
a =income.loc[(income['ApplicantIncome']>=6277) & (income['ApplicantIncome']<=6500)]
#print(a)
plt.figure()
pd.crosstab(a['ApplicantIncome'],a['Loan_Status']).plot.bar()
#a.plot(['ApplicantIncome','Loan_Status'])

pd.crosstab(a['CoapplicantIncome'],a['Loan_Status']).plot.bar()

###############################
##########      min applicant income to get loan is 6000-7000
######################## and there are no much dependency on coaaplicantincome

plt.style.use('ggplot')
plt.figure(figsize=(30,5))
pd.crosstab(df['Education'],df['Loan_Status']).plot.bar()
###################################
#####################conclusion-4 ------- graduate have higher chance of gettinpd.
plt.style.use('fivethirtyeight')

pd.crosstab(df['Credit_History'],df['Loan_Status']).plot.bar()
#####################################################################
####################################################################
#########  THERE IS SIGNIFIACNT DIFERRNCE  ON BASIS OF CREDIT HISTORY
#THE PEOPLES WHICH HAVE CREDIT HISTORY THA HAVE HIGH CHANCES OF GETTING LOAN
plt.style.use('classic')
plt.rc('figure', figsize=(20,5))
ax =pd.crosstab(df['Married'],df['Loan_Status']).plot.bar()



ax.text(0, 330, 'married and unmarried  loan status',fontsize=30,
        bbox={'facecolor':'red','color':'yellow', 'alpha':0.5, 'pad':5})

ax.set_xlabel('married',fontsize=30,color='r',bbox={'facecolor':'blue'})

plt.xticks(fontsize=14, rotation=90)
plt.yticks(fontsize=14, rotation=90)
#############################################################################################################
#conclusion-6 -------  married peoples have high probablity of getting loan then unmarried peoples
########################################################################################################



pd.crosstab(df['Dependents'],df['Loan_Status']).plot.bar()
#######################
# peoples which  have 0 dependents means 0 childerns or siblings have high probbality of getting loan<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.26020731965305693, 'fraction_numerical': 0.01417389464776814, 'mean_word_length': 6.9730185497470485, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '580280', 'license': 'MIT', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1529, 'n_words': 285, 'path': 'Boston Hosuing Dataset/.ipynb_checkpoints/data-exploration-and-data-visualization-checkpoint.ipynb', 'repo_name': 'Vishal1Mishra/Code-perfect', 'size': '4727'}