-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionLibrary.py
More file actions
67 lines (53 loc) · 2.14 KB
/
Copy pathFunctionLibrary.py
File metadata and controls
67 lines (53 loc) · 2.14 KB
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
import pandas as pd
import os
import sys
import warnings
import plotly.express as px
warnings.filterwarnings("ignore")
def check_file(file_path):
if not os.path.isfile(file_path):
print(f'Error: File "{file_path}" not found. Please check if you are in the correct directory.')
sys.exit(1)
return file_path
def clean_loandata(df):
for col in df.select_dtypes(include = 'object'):
if col in df.columns:
df[col].fillna(df[col].mode()[0], inplace = True)
df[col] = df[col].astype('category')
df[col] = df[col].str.strip().str.lower()
for col in df.select_dtypes(include = ['int64', 'float64']):
if col in df.columns:
df[col].fillna(df[col].median(), inplace= True)
upper = df[col].quantile(0.99)
df[col] = df[col].apply(lambda x: upper if x >upper else x).round(2)
return df
def pie_chart(df, column_name):
pie_chart_count = df[column_name].value_counts()
pie_chart_status = px.pie(pie_chart_count, names = pie_chart_count.index,
title = column_name)
pie_chart_status.show()
def bar_graph(df, column_name):
bar_graph_count = df[column_name].value_counts()
fig_bar_graph = px.bar(bar_graph_count,
x=bar_graph_count.index,
y=bar_graph_count.values,
title= column_name+' Distribution')
fig_bar_graph.show()
def histogram(df, column_name):
fig_histogram = px.histogram(df, x = column_name,
title = column_name+' Distribution')
fig_histogram.show()
def box_plot(df, x_column, y_column):
fig_box_plot = px.box(df, x = x_column,y = y_column, color = x_column,
title = x_column + ' vs ' + y_column)
fig_box_plot.show()
Q1 = df[y_column].quantile(0.25)
Q3 = df[y_column].quantile(0.75)
IQR = Q3 -Q1
lower_bound = Q1 -1.5 *IQR
upper_bound = Q3 +1.5 *IQR
df = df[(df[y_column] >= lower_bound) & (df[y_column] <= upper_bound)]
def double_histogram(df, one_name, two_name):
fig_double_histogram = px.histogram(df, x = one_name, color = two_name, barmode = 'group',
title = two_name+' vs '+one_name)
fig_double_histogram.show()