# ---
# 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
# ---

import pandas as pd
import datetime

mega_data = pd.read_csv("final_mega_df.csv")
mega_data.head(25)

list(mega_data.columns)

# +
#issue_d is a string, want to change to datetime format
#first, a dictionary comparing the string of month names to their numerical value

months = {
        'Jan' : 1,
        'Feb' : 2,
        'Mar' : 3,
        'Apr' : 4,
        'May' : 5,
        'Jun' : 6,
        'Jul' : 7,
        'Aug' : 8,
        'Sep' : 9, 
        'Oct' : 10,
        'Nov' : 11,
        'Dec' : 12
}

#save in separate field, and split to two columns
temp = mega_data['issue_d']
temp.str.split('-')
new = mega_data['issue_d'].str.split("-", n = 1, expand = True) 

#change to numerical value and save as Integers
new[0]= new[0].map(months) 
new[1]= new[1].astype(int)

# new['issue_d']= pd.to_datetime(new['issue_d'])
# # new.info()
# -

#change Year value to full numerical year by adding 2000
new[1] = 2000 + new[1]
dates = new
dates

# +
#rename columns
dates.rename(columns = {0: 'Month', 1: 'Year'}, inplace = True)

#convert to datetime format
dates['Full Date'] = pd.to_datetime(dates.assign(Day=1).loc[:, ['Year','Month','Day']])

#add column that just shows Year/Month values, as Day value doesn't matter
dates['issue_dates']= pd.to_datetime(dates['Full Date']).dt.to_period('M')
dates



# +
#merge issue_dates into mega_data and remove issue_d column

mega_data['issue_date']= dates['issue_dates']

mega_data.head()
# -

mega_data.to_csv('mega_data_MR.csv',index=False)

maya_data = mega_data[['ID', 'loan_amnt', 'funded_amnt','int_rate','installment','grade',
                       'issue_date','loan_status','purpose','fico_range_low','fico_range_high',
                      'home_ownership','annual_inc','emp_title','addr_state','dti',
                       'initial_list_status','total_pymnt','total_rec_prncp','total_rec_int']]

maya_data.to_csv('graph_data.csv',index=False)



StarcoderdataJupyterScriptsDedupFiltered