MacMahesh commited on
Commit
754f6cf
·
verified ·
1 Parent(s): a6e1af3

Upload tips.py

Browse files
Files changed (1) hide show
  1. tips.py +42 -0
tips.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import seaborn as sns
3
+ import pandas as pd
4
+
5
+ # Load data
6
+ data = sns.load_dataset("tips")
7
+
8
+ # Page config
9
+ st.set_page_config(page_title='Tips Data Analysis', layout='wide')
10
+
11
+ # Title and description
12
+ st.title('Tips Data Analysis with Streamlit')
13
+ st.write('Tips rise with total bill, but the tip/total_bill ratio goes down as total bill increases.')
14
+ st.write('---')
15
+
16
+ # Sidebar widgets
17
+ with st.sidebar:
18
+ st.subheader('Filter Options')
19
+ threshold = st.slider('Threshold for Total Bill', min_value=0, max_value=100, value=10, step=1)
20
+ day_selector = st.multiselect('Select Day(s)', options=data['day'].unique(), default=data['day'].unique())
21
+
22
+ # Filter data
23
+ filtered_data = data[data['total_bill'] > threshold]
24
+ filtered_data = filtered_data[filtered_data['day'].isin(day_selector)]
25
+
26
+ # Main content
27
+ st.subheader('Total Bill vs Tip Scatter Plot')
28
+
29
+ if not filtered_data.empty:
30
+ current_selected_day = ', '.join(filtered_data['day'].unique())
31
+ st.write(f"Scatter plot for total bill vs tip for {current_selected_day} with total bill above {threshold}.")
32
+ st.write(
33
+ f"You can see current average tip {filtered_data['tip'].mean():.2f} for selected days. "
34
+ f"But tip/total_bill ratio is {(filtered_data['tip']/filtered_data['total_bill']).mean():.2%}"
35
+ )
36
+ st.scatter_chart(data=filtered_data, x='total_bill', y='tip', color='day')
37
+ st.dataframe(filtered_data)
38
+ else:
39
+ st.warning("No data available for the selected filters.")
40
+
41
+ st.write('---')
42
+