File size: 1,855 Bytes
c7f7d04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
754f6cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7f7d04
754f6cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c7f7d04
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
Hugging Face's logo
Hugging Face
Models
Datasets
Spaces
Community
Docs
Pricing



Spaces:

soysouce
/
AAU_Business_Data_Sci


like
1
App
Files
Community
AAU_Business_Data_Sci
/
w2_assign_streamlit.py

soysouce's picture
soysouce
Update w2_assign_streamlit.py
8b9e4c5
VERIFIED
about 18 hours ago
raw

Copy download link
history
blame
contribute
delete

1.49 kB
import streamlit as st
import seaborn as sns
import pandas as pd

# Load data
data = sns.load_dataset("tips")

# Page config
st.set_page_config(page_title='Tips Data Analysis', layout='wide')

# Title and description
st.title('Tips Data Analysis with Streamlit')
st.write('Tips rise with total bill, but the tip/total_bill ratio goes down as total bill increases.')
st.write('---')

# Sidebar widgets
with st.sidebar:
    st.subheader('Filter Options')
    threshold = st.slider('Threshold for Total Bill', min_value=0, max_value=100, value=10, step=1)
    day_selector = st.multiselect('Select Day(s)', options=data['day'].unique(), default=data['day'].unique())

# Filter data
filtered_data = data[data['total_bill'] > threshold]
filtered_data = filtered_data[filtered_data['day'].isin(day_selector)]

# Main content
st.subheader('Total Bill vs Tip Scatter Plot')

if not filtered_data.empty:
    current_selected_day = ', '.join(filtered_data['day'].unique())
    st.write(f"Scatter plot for total bill vs tip for {current_selected_day} with total bill above {threshold}.")
    st.write(
        f"You can see current average tip {filtered_data['tip'].mean():.2f} for selected days. "
        f"But tip/total_bill ratio is {(filtered_data['tip']/filtered_data['total_bill']).mean():.2%}"
    )
    st.scatter_chart(data=filtered_data, x='total_bill', y='tip', color='day')
    st.dataframe(filtered_data)
else:
    st.warning("No data available for the selected filters.")

st.write('---')