File size: 1,050 Bytes
e557ce4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}%**.")