-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_class.py
72 lines (56 loc) · 2.72 KB
/
data_class.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
import numpy as np
import pandas as pd
class Data:
def __init__(self, dataset):
'''loading dataframes'''
self.dataset = dataset
self.process_data()
def process_data(self):
self._create_df()
self._column_info()
self._print_df_stats()
self._check_duplicates()
def _create_df(self):
'''loads and prepares dataframe'''
self.df = self._load_dataset(dataset)
def _column_info(self):
self.cat_cols = self._cat_cols(self.df)
self.num_cols = self._num_cols(self.df)
def _print_df_stats(self):
print(' \n ----------Train Data Info---------')
self.printstats(self.df)
self._check_nan(self.df)
def _load_dataset(self, file):
return pd.read_excel(file)
def printstats(self, df):
print('---------------------------------------------------------')
print('Shape of Dataframe - {}'.format(df.shape))
print('---------------------------------------------------------')
print('\n Dataframe Info: \n')
print('n{}'.format(df.info()))
print('---------------------------------------------------------')
print(' Categorical Features Stats: \n \n{}'.format(df.describe(include='O')))
print('-------------------------------------------------')
print(' Numerical Features Stats:- \n \n{}'.format(df.describe()))
def _check_nan(self, df):
'''Checks and verifies presence of null values in Dataframe'''
nan = np.sum(df.isna().sum())
if nan == 0:
print('\n\n : There are no null values in the dataframes')
else:
print('The following columns have null values\n\n{}'.format(df.isnull().sum()))
def _cat_cols(self, df):
'''finds and lists Categorical Columns in Dataframe'''
self.cat_cols = df.select_dtypes(include=['O']).columns.tolist()
print('Categorical Columns list: {}'.format(self.cat_cols))
print('---------------------------------------------------------------------')
return self.cat_cols
def _num_cols(self, df):
'''finds and lists Numerical Columns in Dataframe'''
self.num_cols = df.select_dtypes(exclude=['O']).columns.tolist()
print('Numerical Columns list: {}'.format(self.num_cols))
print('---------------------------------------------------------------------')
return self.num_cols
def _check_duplicates(self):
'''Checks presence of duplicate entries'''
print('\n : There are {} duplicate values in the Dataframe'.format(self.df.duplicated().sum()))