File size: 1,700 Bytes
357fb69 | 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 49 50 51 52 | import streamlit as st
import pandas as pd
import plotly.express as px
import seaborn as sns
# 1. Page Config
st.set_page_config(page_title="Waiter Tips Analysis", layout="wide")
# 2. Sidebar: Aim & Target (From your Notebook)
st.sidebar.title("Project Overview")
st.sidebar.markdown("""
**Aim:** Identify key factors influencing tipping behavior.
**Target:** - Customer Profiling
- Temporal Analysis
- Correlation Mapping
- Interactive Visualization
""")
# 3. Load Data
@st.cache_data
def load_data():
# You can also use pd.read_csv("waitertips.csv") if you upload the file
df = sns.load_dataset('tips')
df['tip_pct'] = (df['tip'] / df['total_bill']) * 100
return df
df = load_data()
# 4. Main Title
st.title("🍽️ Waiter Tips Data Visualization")
st.write("Exploration of restaurant transactions and tipping patterns.")
# 5. Key Metrics (The "A" you added!)
col1, col2, col3 = st.columns(3)
col1.metric("Avg. Total Bill", f"${df['total_bill'].mean():.2f}")
col2.metric("Avg. Tip", f"${df['tip'].mean():.2f}")
col3.metric("Avg. Tip %", f"{df['tip_pct'].mean():.2f}%")
# 6. Interactive Plotly Chart (The "B" you added!)
st.subheader("Interactive Tip Analysis")
fig = px.scatter(df, x="total_bill", y="tip", color="sex",
size="size", hover_data=['day', 'time'],
trendline="ols", title="Total Bill vs Tip (by Gender)")
st.plotly_chart(fig, use_container_width=True)
# 7. Advanced Visualization (Sunburst)
st.subheader("Hierarchical View of Tips")
fig_sun = px.sunburst(df, path=['day', 'time', 'sex'], values='tip')
st.plotly_chart(fig_sun, use_container_width=True)
st.write("---")
st.write("Created for my Data Visualization Portfolio.") |