<jupyter_start><jupyter_text>Author: <NAME> Reg No: 20MAI0044 **Dataset II : loan.csv** **Assignment on feature engineering**<jupyter_code># Importing the necessary libraries
import numpy as np
import pandas as pd
# Lets get the data inside our dataframe
data = pd.read_csv('Data/loan.csv')
data.shape
# And see what our data looks like
data.head()
# Also what is the data type of the features available?
data.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 10000 entries, 0 to 9999
Data columns (total 14 columns):
 #   Column                  Non-Null Count  Dtype  
---  ------                  --------------  -----  
 0   customer_id             10000 non-null  int64  
 1   disbursed_amount        10000 non-null  float64
 2   interest                10000 non-null  float64
 3   market                  10000 non-null  object 
 4   employment              9389 non-null   object 
 5   time_employed           9471 non-null   object 
 6   householder             10000 non-null  object 
 7   income                  10000 non-null  float64
 8   date_issued             10000 non-null  object 
 9   target                  10000 non-null  int64  
 10  loan_purpose            10000 non-null  object 
 11  number_open_accounts    10000 non-null  float64
 12  date_last_payment       10000 non-null  object 
 13  number_credit_lines_12  238 non-null    float64
dtypes: float64(5), int64(2), object(7)
memo[...]<jupyter_text>Continuous Variables<jupyter_code># Here income and disbursed_amount are features with continuous values
print(data['income'].mean())
print(data['disbursed_amount'].mean())
#data.groupby('disbursed_amount').mean()
#print(data['disbursed_amount'].value_counts())<jupyter_output><empty_output><jupyter_text>Discrete Variables<jupyter_code>cat_features=[i for i in data.columns if data.dtypes[i]=='object']
cat_features
print(data['market'].unique())
print(data['employment'].unique())
print(data['householder'].unique())
print(data['householder'].value_counts())
data[['date_issued','date_last_payment']].dtypes
data['date_issued_dt'] = pd.to_datetime(data['date_issued'])
data['date_last_payment_dt'] = pd.to_datetime(data['date_last_payment'])
#Extract Month from the date
data['month']= data['date_issued_dt'].dt.month
data.head()
print(data['month'].value_counts())
data['month'].value_counts()[:1].index.tolist()
for name, group in data.groupby(['employment', 'householder']):
    if(name[0]=='Teacher' and name[1]=='OWNER'):
        print(name)
        print(group)
data.groupby('employment')['householder'].apply(lambda ser: ser.str.contains("OWNER").sum())<jupyter_output><empty_output><jupyter_text>Here we can see that there are 69 teachers who are owners as well<jupyter_code># And we can verify another way as well 
data.groupby('householder')['employment'].apply(lambda ser: ser.str.contains("Teacher").sum())
data.groupby('employment')['householder'].apply(lambda ser: ser.str.contains("RENT").sum())
data.groupby('employment',sort=False)['householder'].apply(lambda ser: ser.str.contains("RENT").sum())<jupyter_output><empty_output><jupyter_text>And employment of customers who mostly rent is Teacher and Civil Servant<jupyter_code>data.groupby('householder')['employment'].apply(lambda ser: ser.str.contains("Teacher").sum())
data.groupby('householder')['employment'].apply(lambda ser: ser.str.contains("Civil Servant").sum())
data.groupby('householder')['employment'].apply(lambda ser: ser.str.contains("Taxi driver").sum())
data.groupby('householder')['employment'].apply(lambda ser: ser.str.contains("Software developer").sum())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14092664092664092, 'fraction_numerical': 0.035852178709321565, 'mean_word_length': 4.42152466367713, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '617290', 'license': 'MIT', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1097, 'n_words': 254, 'path': 'ML_Lab_Assignment2_2.ipynb', 'repo_name': 'tejaswini212/ML-Techniques---Lab', 'size': '3635'}