Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
# This cell is used to make new column called 'group_age' | |
def filter_group_age(age): | |
if 0 <= age <= 14: | |
return "children" | |
elif 15 <= age <= 24: | |
return "youth" | |
elif 25 <= age <= 64: | |
return "adults" | |
elif age >= 65: | |
return "seniors" | |
else: | |
return "unknown" | |
def run(): | |
st.title('Credit Card Payment Exploration Data Analyst(EDA)') | |
st.image('https://www.i1.creditdonkey.com/image/1/[email protected]') | |
st.write('This page is made by Yudis Aditya') | |
st.markdown('---') | |
st.write('In this page, I want to show visualization data based on my analyst process about credit card payment. This EDA has information about customer segmentation and customer behaviour') | |
st.link_button('Link dataset','https://console.cloud.google.com/bigquery?p=bigquery-public-data&d=ml_datasets&t=credit_card_default&page=table&project=direct-keel-424102-f5&ws=!1m5!1m4!4m3!1sbigquery-public-data!2sml_datasets!3scredit_card_default') | |
df = pd.read_csv('P1G5_Set_1_yudis_aditya.csv') | |
df['group_age'] = df['age'].apply(filter_group_age) | |
st.write('## Customer Segmentation') | |
st.write('### Distribution Data Age') | |
# This cell is used to create histogram column age | |
data = df['age'] | |
fig = plt.figure(figsize=(15,5)) | |
plt.hist(x=data) | |
plt.title("Distribution Data Age") | |
plt.show() | |
st.pyplot(plt) | |
st.write("From Graph 'Distribution Data Age' we can see that the most client who use credit card have age around 20 - 40") | |
st.write('Based on Standarization Statistic Canada, we can make group of age like this :') | |
st.write('- 0 - 14 = children ') | |
st.write('- 15 - 24 = youth') | |
st.write('- 25 - 64 = adults ') | |
st.write('- more than equal 65 = seniors') | |
data = df.groupby('group_age').size() | |
x = data.index | |
y = data.values | |
fig = plt.figure(figsize=(15,5)) | |
plt.pie(y,labels=x,autopct='%1.1f%%') | |
plt.title("Pie Chart Data based on Group Age") | |
st.pyplot(plt) | |
st.write('From Graph "Distribution Data Group Age" we can know that majority significant people who use credit card is in group age adults. and The second is youth but not really significant. And group age "seniors" is rare to use credit card. So i dont recommend to target youth and seniors for promotion') | |
st.write('### Distribution Data Marital Status') | |
# This cell is used to create pie graph to know distibution data based on marital_status | |
data = df[df['marital_status'] != 0].groupby('marital_status').size() | |
x = ['married','single','others'] | |
y = data.values | |
fig = plt.figure(figsize=(15,5)) | |
plt.pie(y,labels=x,autopct='%1.1f%%') | |
plt.title("Distribution data person based on marital status") | |
st.pyplot(fig) | |
st.write('From Graph above we can see that person who single is more to use credit card than married. person who has marital_status others has not really significant. So i recommend to make promotion product like accesoris, game, outfit, etc that related for increase status social with using pay credit') | |
st.write('### Distribution Data Gender') | |
data = df.groupby('sex').size() | |
x = ['male','female'] | |
y = data.values | |
fig = plt.figure(figsize=(15,5)) | |
plt.pie(y,labels=x,autopct='%1.1f%%') | |
plt.title("Distribution data person based on gender") | |
st.pyplot(fig) | |
st.write('From Graph above we can see that female is more using credit card than male. So we can make promotion for product that used for woman with pay using credit.') | |
st.write('## Customer Behaviour') | |
st.write('### Total People who pay duly on April - September in 2005') | |
fig = plt.figure(figsize=(15,5)) | |
# This cell is used to create line chart to know total status payment duly in 2005 | |
data_6 = df[(df['pay_6'] <= 0)][['pay_6']].count() | |
data_5 = df[(df['pay_5'] <= 0)][['pay_5']].count() | |
data_4 = df[(df['pay_4'] <= 0)][['pay_4']].count() | |
data_3 = df[(df['pay_3'] <= 0)][['pay_3']].count() | |
data_2 = df[(df['pay_2'] <= 0)][['pay_2']].count() | |
data_1 = df[(df['pay_0'] <= 0)][['pay_0']].count() | |
data_input = { | |
'Apr':data_1.values[0], | |
'May':data_2.values[0], | |
'Jun':data_3.values[0], | |
'July':data_4.values[0], | |
'August':data_5.values[0], | |
'Sep':data_6.values[0], | |
} | |
data_visualize = pd.DataFrame([data_input]) | |
data_visualize.values.tolist()[0] | |
# print(data) | |
x = data_visualize.columns.to_list() | |
y = data_visualize.values.tolist()[0] | |
plt.plot(x,y) | |
plt.title("Total status payment duly in 2005") | |
st.pyplot(fig) | |
st.write('From Graph above we can know that Total people who pay duly are increased significant from April 2005 until September 2005. It indicate that client has good behaviour to pay their bill, so the way to selection client who can have credit card is already good.') | |
st.write('### Median Bill Amount on April - September in 2005') | |
fig = plt.figure(figsize=(15,5)) | |
# This cell is used to create line chart to know total status payment duly in 2005 | |
data_6 = df[['bill_amt_6']].median() | |
data_5 = df[['bill_amt_5']].median() | |
data_4 = df[['bill_amt_4']].median() | |
data_3 = df[['bill_amt_3']].median() | |
data_2 = df[['bill_amt_2']].median() | |
data_1 = df[['bill_amt_1']].median() | |
data_input = { | |
'Apr':data_1.values[0], | |
'May':data_2.values[0], | |
'Jun':data_3.values[0], | |
'July':data_4.values[0], | |
'August':data_5.values[0], | |
'Sep':data_6.values[0], | |
} | |
data_visualize = pd.DataFrame([data_input]) | |
data_visualize.values.tolist()[0] | |
# print(data) | |
x = data_visualize.columns.to_list() | |
y = data_visualize.values.tolist()[0] | |
plt.bar(x,y) | |
plt.title("Median Bill amount from April - September 2005") | |
st.pyplot(fig) | |
st.write('From graph above i use median instead mean because distribution data is not normal. We can see that median bill amount from april until September is decrased. That visualize that most people has decrased bill amount every month, which is good. ') | |
st.write('### Total people who pay and not pay for next month (October) 2005') | |
fig = plt.figure(figsize=(15,5)) | |
data_input = df.groupby(['default_payment_next_month']).size() | |
x = ['Pay','Not Pay'] | |
y = data_input.values | |
plt.bar(x,y) | |
plt.title('Total people who pay and dont pay on October 2005') | |
st.pyplot(fig) | |
st.write('From Graph above we know that more people pay for next month (October) than not pay. It is good result because that indicate client good behaviour and prove that process selection client who can use credit card is success.') | |
st.markdown('---') | |
st.write('# Conclusion') | |
st.write('From analysis and creating visualize from my dataset , This is a important point that i can share:') | |
st.write("- For promotion , don't target for group age old and young. And we can make deal promotion with product that focus on increase status life style like accesoris, outfit, etc using credit card. Also deal promotion with product that related with woman like makeup, salon , etc.") | |
st.write('- For April until September 2005, we can see that our client summarize has good behavior because dominant pay dully and decrase bill amount for every month. It is indicate the process selection client who can use credit card is good.') | |
if __name__ == '__main__': | |
run() | |