-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_analysis.py
149 lines (121 loc) · 5.39 KB
/
data_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# %matplotlib inline
X_test = pd.read_csv("interbank-internacional-2019/ib_base_inicial_test/ib_base_inicial_test.csv", parse_dates=["codmes"])
campanias = pd.read_csv("interbank-internacional-2019/ib_base_campanias/ib_base_campanias.csv", parse_dates=["codmes"])
digital = pd.read_csv("interbank-internacional-2019/ib_base_digital/ib_base_digital.csv", parse_dates=["codday"])
rcc = pd.read_csv("interbank-internacional-2019/ib_base_rcc/ib_base_rcc.csv", parse_dates=["codmes"])
reniec = pd.read_csv("interbank-internacional-2019/ib_base_reniec/ib_base_reniec.csv")
sunat = pd.read_csv("interbank-internacional-2019/ib_base_sunat/ib_base_sunat.csv")
vehicular = pd.read_csv("interbank-internacional-2019/ib_base_vehicular/ib_base_vehicular.csv")
train = pd.read_csv("interbank-internacional-2019/ib_base_inicial_train/ib_base_inicial_train.csv" , parse_dates=["codmes"])
#
# Number of data
#
print('Forma del csv campanias', campanias.shape)
print('Forma del csv digital', digital.shape)
print('Forma del csv rcc', rcc.shape)
print('Forma del csv reniec', reniec.shape)
print('Forma del csv sunat', sunat.shape)
print('Forma del csv vehicular', vehicular.shape)
print("")
print(rcc.producto.value_counts())
#
# Null Inputs in RCC data
#
total = rcc.isnull().sum().sort_values(ascending = False)
percent = (rcc.isnull().sum()/rcc.isnull().count()*100).sort_values(ascending = False)
missing_application_train_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
print("")
print(missing_application_train_data.head(6))
#
# Comparision Train and Test
#
print(train.shape, X_test.shape) # train has target and test not
#
# Null check
#
total = train.isnull().sum().sort_values(ascending = False)
percent = (train.isnull().sum()/train.isnull().count()*100).sort_values(ascending = False)
missing_application_train_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
print("\n#####")
print("# Train:\n")
print(missing_application_train_data.head(20))
total = X_test.isnull().sum().sort_values(ascending = False)
percent = (X_test.isnull().sum()/X_test.isnull().count()*100).sort_values(ascending = False)
missing_application_train_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
print("\n#####")
print("# Test:\n")
print(missing_application_train_data.head(20))
total = campanias.isnull().sum().sort_values(ascending = False)
percent = (campanias.isnull().sum()/campanias.isnull().count()*100).sort_values(ascending = False)
missing_application_train_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
print("\n#####")
print("# Campanias:\n")
print(missing_application_train_data.head(20))
total = digital.isnull().sum().sort_values(ascending = False)
percent = (digital.isnull().sum()/digital.isnull().count()*100).sort_values(ascending = False)
missing_application_train_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
print("\n#####")
print("# Digital:\n")
print(missing_application_train_data.head(6))
total = reniec.isnull().sum().sort_values(ascending = False)
percent = (reniec.isnull().sum()/reniec.isnull().count()*100).sort_values(ascending = False)
missing_application_train_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
print("\n#####")
print("# Reniec:\n")
print(missing_application_train_data.head(3))
total = sunat.isnull().sum().sort_values(ascending = False)
percent = (sunat.isnull().sum()/sunat.isnull().count()*100).sort_values(ascending = False)
missing_application_train_data = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
print("\n#####")
print("Sunat:\n")
print(missing_application_train_data.head(6))
train['codmes'] = pd.to_datetime(train['codmes'], format='%Y%m')
train['codmes'] = pd.to_datetime(train['codmes'] ).dt.to_period('M')
print("")
print(train.head())
sns.countplot(train['codtarget'], palette='Set3')
print("")
print("There are ", round(100*train["codtarget"].value_counts()[1]/train.shape[0],2), "% of regists that we want (1)")
print(train.codmes.value_counts())
X_test['codmes'] = pd.to_datetime(X_test['codmes'], format='%Y%m')
X_test['codmes'] = pd.to_datetime(X_test['codmes']).dt.to_period('M')
print("")
print("Test")
print(X_test.codmes.value_counts())
campanias['codmes'] = pd.to_datetime(campanias['codmes'], format='%Y%m')
campanias['codmes'] = pd.to_datetime(campanias['codmes']).dt.to_period('M')
print("")
print("CAMPANIAS")
print(campanias.codmes.value_counts())
digital['codday'] = pd.to_datetime(digital['codday'], format='%Y%m%d')
digital['codday'] = pd.to_datetime(digital['codday']).dt.to_period('M')
print("")
print("DIGITAL")
print(digital.codday.value_counts())
rcc['codmes'] = pd.to_datetime(rcc['codmes'], format='%Y%m')
rcc['codmes']= pd.to_datetime(rcc['codmes']).dt.to_period('M')
print("")
print("RCC")
print(rcc.codmes.value_counts())
#
# Explore RCC
#
# ['codmes', 'id_persona', 'cod_banco', 'producto', 'clasif', 'mto_saldo', 'rango_mora']
print(rcc.columns.tolist())
print(rcc.loc[rcc['id_persona'] == 1])
print(rcc.loc[rcc['id_persona'] == 2])
print(rcc.loc[rcc['id_persona'] == 3])
print(rcc.loc[rcc['id_persona'] == 4])
print(rcc.loc[rcc['id_persona'] == 5])
print(rcc.producto.unique())
print(rcc.clasif.unique())
print(rcc.mto_saldo.unique())
print(rcc.rango_mora.unique())
print("#####")
print(campanias.producto.unique())
print("#####")
print(digital.codday.unique())