File size: 1,074 Bytes
fe8f546
 
8fea24b
fe8f546
 
 
 
80abd95
fe8f546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ac990b
 
 
 
fe8f546
 
 
 
 
 
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
import streamlit as st 
import pandas as pd
pip install openpyxl

st.title("Customer Lifetime Value App")

# Read the dataset
data = pd.read_excel('online_retail_II.xlsx')

# Get the user id
user_id = st.selectbox('Select the user id :', data.CustomerID.unique())

# Get the data for the selected user id
user_data = data[data['CustomerID'] == user_id]

# Calculate the CLV
clv = (user_data.UnitPrice * user_data.Quantity).sum()

st.write('Customer lifetime value : ', clv)

# Calculate the next purchase date
purchase_date = user_data.InvoiceDate.max()

st.write('Next purchase date : ', purchase_date)

# Get the purchase trend
user_data['InvoiceDate'] = pd.to_datetime(user_data['InvoiceDate'])
user_data['Day'] = user_data['InvoiceDate'].dt.day
user_data['Month'] = user_data['InvoiceDate'].dt.month
user_data['Week'] = user_data['InvoiceDate'].dt.week
user_data['Year'] = user_data['InvoiceDate'].dt.year

# Plot the graphs
st.subheader('Purchase Trend')









# Risk of Churn
if clv <= 0:
    st.write('Risk of Churn : Yes')
else:
    st.write('Risk of Churn : No')