import streamlit as st import seaborn as sns import pandas as pd import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset("tips") df["tip_pct"] = df["tip"] / df["total_bill"] * 100 # --- App layout --- st.title("🍽️ Tips Data Explorer") st.write("This app helps you explore tipping behavior.") # Sidebar controls st.sidebar.header("Filters") day = st.sidebar.selectbox("Select a day:", df["day"].unique()) time = st.sidebar.radio("Select time:", df["time"].unique()) # Filter data filtered = df[(df["day"] == day) & (df["time"] == time)] # KPI (average tip %) avg_tip = filtered["tip_pct"].mean() st.metric(label=f"Average Tip % on {day} ({time})", value=f"{avg_tip:.2f}%") # Visualization fig, ax = plt.subplots() ax.hist(filtered["tip_pct"], bins=10, color="skyblue", edgecolor="black") ax.set_title(f"Tip % Distribution on {day} ({time})") ax.set_xlabel("Tip Percentage") ax.set_ylabel("Count") st.pyplot(fig) # Dynamic insight st.write(f"💡 On **{day} {time}**, the average tip percentage is around **{avg_tip:.2f}%**.")