gilangw commited on
Commit
ad2e352
·
1 Parent(s): d09ce4f

Upload eda.py

Browse files
Files changed (1) hide show
  1. eda.py +11 -7
eda.py CHANGED
@@ -13,7 +13,7 @@ def run():
13
 
14
  st.title('Exploratory Data Analysis')
15
  plot_selection = st.selectbox(label='Choose',
16
- options=['Customer Distribution',
17
  'Churn by Monthly Charge',
18
  'Churn by Tenure',
19
  'Churn by Internet Service'])
@@ -22,16 +22,20 @@ def run():
22
  def plot_1():
23
  st.write('#### Pie Chart for Customer Status Distribution')
24
  target = df.groupby(['churn']).agg(total_churn=('churn', 'count'))
 
25
  target['percentage'] = (target['total_churn'] / target['total_churn'].sum())
26
-
27
- fig_1 = plt.figure()
28
- fig_1, ax = plt.subplots(ncols=1, figsize=(5, 5))
29
- ax.pie(target["percentage"], labels=target["percentage"].index, autopct='%.0f%%')
30
- ax.set_title("Customer Status Distribution")
 
 
31
  st.pyplot(fig_1)
32
  st.write('''
33
  From the plot above, it is found that of the total number of customers who churn
34
  is 27% (1869 customers) and customers who is not churn / stay is 73% (5163 customers).
 
35
  ''')
36
  st.markdown('---')
37
 
@@ -76,7 +80,7 @@ def run():
76
  st.markdown('---')
77
 
78
 
79
- if plot_selection == "Customer Distribution":
80
  plot_1()
81
  elif plot_selection == "Churn by Monthly Charge":
82
  plot_2()
 
13
 
14
  st.title('Exploratory Data Analysis')
15
  plot_selection = st.selectbox(label='Choose',
16
+ options=['Customer Demographic',
17
  'Churn by Monthly Charge',
18
  'Churn by Tenure',
19
  'Churn by Internet Service'])
 
22
  def plot_1():
23
  st.write('#### Pie Chart for Customer Status Distribution')
24
  target = df.groupby(['churn']).agg(total_churn=('churn', 'count'))
25
+ gender = df.groupby(['gender']).agg(total_gender=('gender', 'count'))
26
  target['percentage'] = (target['total_churn'] / target['total_churn'].sum())
27
+
28
+ fig_1, ax = plt.subplots(nrows=1, ncols=2, figsize=(10, 5))
29
+ ax[0].pie(target["total_churn"], labels=target["total_churn"].index, autopct='%.0f%%')
30
+ ax[0].set_title("Churn and No-Churn")
31
+ ax[1].pie(gender["total_gender"], labels=gender["total_gender"].index, autopct='%.1f%%')
32
+ ax[1].set_title("Customer Gender")
33
+
34
  st.pyplot(fig_1)
35
  st.write('''
36
  From the plot above, it is found that of the total number of customers who churn
37
  is 27% (1869 customers) and customers who is not churn / stay is 73% (5163 customers).
38
+ From all the customer 50.5% is male and 49.5% is female.
39
  ''')
40
  st.markdown('---')
41
 
 
80
  st.markdown('---')
81
 
82
 
83
+ if plot_selection == "Customer Demographic":
84
  plot_1()
85
  elif plot_selection == "Churn by Monthly Charge":
86
  plot_2()