# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# this notebook will extract the relevant dataset from Kaggle dataset to predict default

import pandas as pd

df = pd.read_csv('loan.csv')

len(df)

df.head()

df.columns

df[df.index<10].to_csv('sample.csv')

df.loan_status.unique()

in_default = ['Charged Off', 'Default', 'Late (31-120 days)', 'Late (16-30 days)', 'Does not meet the credit policy. Status:Charged Off']

len(in_default)

df['in_default'] = df.loan_status.map(lambda x: 1 if x in in_default else 0)

df.in_default.unique()

len(df[df.in_default==1]) / len(df)

cols = ['loan_amnt', 'funded_amnt', 'funded_amnt_inv',
       'term', 'int_rate', 'installment', 'grade', 'sub_grade', 'emp_title',
       'emp_length', 'home_ownership', 'annual_inc', 'verification_status',
       'issue_d', 'loan_status', 'pymnt_plan', 'desc', 'purpose',
       'title', 'zip_code', 'addr_state', 'dti', 'delinq_2yrs',
       'earliest_cr_line', 'inq_last_6mths', 
       'mths_since_last_record', 'open_acc', 'pub_rec', 'revol_bal',
       'revol_util', 'total_acc', 'initial_list_status', 'out_prncp',
       'out_prncp_inv', 'total_pymnt', 'total_pymnt_inv', 'last_pymnt_amnt',
       'next_pymnt_d', 'last_credit_pull_d', 'collections_12_mths_ex_med',
       'mths_since_last_major_derog', 'policy_code', 'application_type',
       'annual_inc_joint', 'dti_joint', 'verification_status_joint', 'in_default']

df[cols].to_csv('default.csv', index=False)

# +
# df1 = pd.DataFrame(cols)

# +
# df1.to_csv('desc.csv', index=False)
# -



StarcoderdataJupyterScriptsDedupFiltered