| import streamlit as st |
| import seaborn as sns |
| import pandas as pd |
| import matplotlib.pyplot as plt |
|
|
| |
| df = sns.load_dataset("tips") |
| df["tip_pct"] = df["tip"] / df["total_bill"] * 100 |
|
|
| |
| st.title("🍽️ Tips Data Explorer") |
| st.write("This app helps you explore tipping behavior.") |
|
|
| |
| st.sidebar.header("Filters") |
| day = st.sidebar.selectbox("Select a day:", df["day"].unique()) |
| time = st.sidebar.radio("Select time:", df["time"].unique()) |
|
|
| |
| filtered = df[(df["day"] == day) & (df["time"] == time)] |
|
|
| |
| avg_tip = filtered["tip_pct"].mean() |
| st.metric(label=f"Average Tip % on {day} ({time})", value=f"{avg_tip:.2f}%") |
|
|
| |
| 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) |
|
|
| |
| st.write(f"💡 On **{day} {time}**, the average tip percentage is around **{avg_tip:.2f}%**.") |
|
|