eoroot1974's picture
Update app.py
4e7a0cd verified
raw
history blame contribute delete
983 Bytes
import pandas as pd
import streamlit as st
from datasets import load_dataset
# Load dataset from Hugging Face
dataset = load_dataset("eoroot1974/demos_d_retail_cust_purchases")
df = dataset['train'].to_pandas()
df['PurchaseDate'] = pd.to_datetime(df['PurchaseDate'])
df['Month'] = df['PurchaseDate'].dt.to_period('M')
# Insights
top_products = df['ProductName'].value_counts().head(10)
top_customers = df.groupby('CustomerName')['AmountSpent'].sum().sort_values(ascending=False).head(10)
monthly_revenue = df.groupby('Month')['AmountSpent'].sum()
# Streamlit Dashboard
st.title("Purchase Recommendation Dashboard")
st.header("Top 10 Purchased Products")
st.bar_chart(top_products)
st.header("Top Spending Customers")
st.bar_chart(top_customers)
st.header("Monthly Revenue")
st.line_chart(monthly_revenue)
st.header("Distribution of Purchase Amounts")
st.histogram_chart(df['AmountSpent'])
st.header("Customer Engagement")
st.histogram_chart(df['CustomerName'].value_counts())