import streamlit as st import pandas as pd import matplotlib.pyplot as plt st.title("Customer Lifetime Value App") # Read the dataset data = pd.read_csv('Online Retail.csv', encoding= 'unicode_escape') st.write(data) data['InvoiceDate'] = pd.to_datetime(data['InvoiceDate']) data["value"] = data.UnitPrice * data.Quantity # 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) # Plot the graphs st.subheader('Purchase Trend') gr = user_data.groupby(user_data["InvoiceDate"].dt.floor("30D")).sum() fig = plt.figure() ax = fig.add_subplot(1,1,1) plt.scatter(x=gr.index, y=gr["value"], c=gr["value"]<0) st.write(fig) # Risk of Churn if clv <= 0: st.write('Risk of Churn : Yes') else: st.write('Risk of Churn : No')