deepakkaura26 commited on
Commit
fe8f546
·
1 Parent(s): 0ccea66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py CHANGED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import plotly.graph_objects as go
5
+
6
+ st.title("Customer Lifetime Value App")
7
+
8
+ # Read the dataset
9
+ data = pd.read_excel('Online Retail.xlsx')
10
+
11
+ # Get the user id
12
+ user_id = st.selectbox('Select the user id :', data.CustomerID.unique())
13
+
14
+ # Get the data for the selected user id
15
+ user_data = data[data['CustomerID'] == user_id]
16
+
17
+ # Calculate the CLV
18
+ clv = (user_data.UnitPrice * user_data.Quantity).sum()
19
+
20
+ st.write('Customer lifetime value : ', clv)
21
+
22
+ # Calculate the next purchase date
23
+ purchase_date = user_data.InvoiceDate.max()
24
+
25
+ st.write('Next purchase date : ', purchase_date)
26
+
27
+ # Get the purchase trend
28
+ user_data['InvoiceDate'] = pd.to_datetime(user_data['InvoiceDate'])
29
+ user_data['Day'] = user_data['InvoiceDate'].dt.day
30
+ user_data['Month'] = user_data['InvoiceDate'].dt.month
31
+ user_data['Week'] = user_data['InvoiceDate'].dt.week
32
+ user_data['Year'] = user_data['InvoiceDate'].dt.year
33
+
34
+ # Plot the graphs
35
+ st.subheader('Purchase Trend')
36
+
37
+ # Day Wise
38
+ fig = go.Figure()
39
+ fig.add_trace(go.Scatter(x=user_data.Day, y=user_data.Quantity, mode='lines+markers', name='Day Wise'))
40
+ st.plotly_chart(fig)
41
+
42
+ # Date Wise
43
+ fig1 = px.line(user_data, x="InvoiceDate", y="Quantity", title='Date Wise')
44
+ st.plotly_chart(fig1)
45
+
46
+ # Week Wise
47
+ fig2 = go.Figure()
48
+ fig2.add_trace(go.Scatter(x=user_data.Week, y=user_data.Quantity, mode='lines+markers', name='Week Wise'))
49
+ st.plotly_chart(fig2)
50
+
51
+ # Month Wise
52
+ fig3 = go.Figure()
53
+ fig3.add_trace(go.Scatter(x=user_data.Month, y=user_data.Quantity, mode='lines+markers', name='Month Wise'))
54
+ st.plotly_chart(fig3)
55
+
56
+ # Risk of Churn
57
+ if clv <= 0:
58
+ st.write('Risk of Churn : Yes')
59
+ else:
60
+ st.write('Risk of Churn : No')