Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import streamlit as st
|
|
| 9 |
|
| 10 |
# Load dataset
|
| 11 |
tips = sns.load_dataset("tips")
|
| 12 |
-
tips["
|
| 13 |
|
| 14 |
# User question
|
| 15 |
st.title("π‘ Do people tip more on certain days of the week?")
|
|
@@ -38,20 +38,20 @@ if selected_time != "All":
|
|
| 38 |
|
| 39 |
|
| 40 |
# KPI: average tip percentage
|
| 41 |
-
avg_tip = filtered["
|
| 42 |
st.metric("For selected days and time , Average Tip %", f"{avg_tip:.2f}%")
|
| 43 |
|
| 44 |
# Visualization
|
| 45 |
if not filtered.empty:
|
| 46 |
plt.figure(figsize=(6,4))
|
| 47 |
-
sns.boxplot(x="day", y="
|
| 48 |
plt.title("Tip Percentage by Day")
|
| 49 |
st.pyplot(plt.gcf())
|
| 50 |
plt.close()
|
| 51 |
|
| 52 |
# Dynamic insight
|
| 53 |
-
best_day = filtered.groupby("day")["
|
| 54 |
-
best_value = filtered.groupby("day")["
|
| 55 |
st.success(f"π‘ Insight: On average, for {selected_time}, {best_day} has the highest tip percentage at {best_value:.2f}%")
|
| 56 |
else:
|
| 57 |
st.info("No data available for the selected filters.")
|
|
|
|
| 9 |
|
| 10 |
# Load dataset
|
| 11 |
tips = sns.load_dataset("tips")
|
| 12 |
+
tips["tip_percentage"] = tips["tip"] / tips["total_bill"] * 100
|
| 13 |
|
| 14 |
# User question
|
| 15 |
st.title("π‘ Do people tip more on certain days of the week?")
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
# KPI: average tip percentage
|
| 41 |
+
avg_tip = filtered["tip_percentage"].mean()
|
| 42 |
st.metric("For selected days and time , Average Tip %", f"{avg_tip:.2f}%")
|
| 43 |
|
| 44 |
# Visualization
|
| 45 |
if not filtered.empty:
|
| 46 |
plt.figure(figsize=(6,4))
|
| 47 |
+
sns.boxplot(x="day", y="tip_percentage", data=filtered, order=all_days)
|
| 48 |
plt.title("Tip Percentage by Day")
|
| 49 |
st.pyplot(plt.gcf())
|
| 50 |
plt.close()
|
| 51 |
|
| 52 |
# Dynamic insight
|
| 53 |
+
best_day = filtered.groupby("day")["tip_percentage"].mean().idxmax()
|
| 54 |
+
best_value = filtered.groupby("day")["tip_percentage"].mean().max()
|
| 55 |
st.success(f"π‘ Insight: On average, for {selected_time}, {best_day} has the highest tip percentage at {best_value:.2f}%")
|
| 56 |
else:
|
| 57 |
st.info("No data available for the selected filters.")
|