Spaces:
Sleeping
Sleeping
Upload my_app_assignment.py
Browse files- my_app_assignment.py +10 -3
my_app_assignment.py
CHANGED
|
@@ -46,9 +46,16 @@ ax2.set_xlabel("Total Bill")
|
|
| 46 |
ax2.set_ylabel("Tip Percentage (%)")
|
| 47 |
ax2.grid(True, linestyle="--", alpha=0.5)
|
| 48 |
st.pyplot(fig2)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
# Plot 3 — Tip Percentage by Smoking Status
|
| 54 |
fig3, ax3 = plt.subplots(figsize=(6,4)) # match Colab size
|
|
|
|
| 46 |
ax2.set_ylabel("Tip Percentage (%)")
|
| 47 |
ax2.grid(True, linestyle="--", alpha=0.5)
|
| 48 |
st.pyplot(fig2)
|
| 49 |
+
# --- Calculate dynamic interpretation ---
|
| 50 |
+
avg_tip_male = filtered[filtered["sex"]=="Male"]["tip_pct"].mean()
|
| 51 |
+
avg_tip_female = filtered[filtered["sex"]=="Female"]["tip_pct"].mean()
|
| 52 |
+
|
| 53 |
+
st.markdown(
|
| 54 |
+
f"**Interpretation:** For the selected filters, the average tip percentage for males is {avg_tip_male:.2f}% "
|
| 55 |
+
f"and for females is {avg_tip_female:.2f}%. "
|
| 56 |
+
"The scatter plot shows that as the total bill increases, tip percentage tends to decrease, "
|
| 57 |
+
"although there are some cases where smaller bills have higher tip percentages."
|
| 58 |
+
)
|
| 59 |
|
| 60 |
# Plot 3 — Tip Percentage by Smoking Status
|
| 61 |
fig3, ax3 = plt.subplots(figsize=(6,4)) # match Colab size
|