MacMahesh commited on
Commit
c314050
Β·
verified Β·
1 Parent(s): 2429d44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -9,7 +9,7 @@ import streamlit as st
9
 
10
  # Load dataset
11
  tips = sns.load_dataset("tips")
12
- tips["tip_pct"] = tips["tip"] / tips["total_bill"] * 100
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["tip_pct"].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_pct", 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_pct"].mean().idxmax()
54
- best_value = filtered.groupby("day")["tip_pct"].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.")
 
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.")