import streamlit as st import pandas as pd st.title("Customer Lifetime Value App") # Read the dataset data = pd.read_csv('Online Retail.csv') # 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')