Quetiento commited on
Commit
b334b83
1 Parent(s): 416e8ab

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -43
app.py CHANGED
@@ -1,43 +1,49 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import matplotlib.pyplot as plt
4
- import seaborn as sns
5
-
6
- # read the dataset
7
- df = pd.read_csv('diamonds.csv')
8
-
9
- st.title('Diamond APP sorting festivity')
10
-
11
- df = df.drop(["Unnamed: 0"], axis=1)
12
-
13
- #Potential diamonds with a impossible dimensions are dropped, for example a diamond that has a 0 in x, y or z should not be possible.
14
- df = df.drop(df[df["x"]==0].index)
15
- df = df.drop(df[df["y"]==0].index)
16
- df = df.drop(df[df["z"]==0].index)
17
- st.image('diamonds.jpg')
18
- st.write(f"the price range is {326} to {18823}")
19
- # users set the price range
20
- min_price = st.number_input('Input minimum price', min_value=int(df['price'].min()), max_value=int(df['price'].max()), value=int(df['price'].min()))
21
- max_price = st.number_input('Input maximum price', min_value=int(df['price'].min()), max_value=int(df['price'].max()), value=int(df['price'].max()))
22
-
23
- #users select
24
- selected_cuts = st.multiselect('choosing cut', df['cut'].unique())
25
- selected_cuts = st.multiselect('choosing color', df['color'].unique())
26
- selected_cuts = st.multiselect('choosing clarity', df['clarity'].unique())
27
- selected_cuts = st.multiselect('choosing carat', df['carat'].unique())
28
-
29
-
30
- # select the diamonds
31
- filtered_diamonds = df[(df['price'] >= min_price) & (df['price'] <= max_price)]
32
-
33
- # show the results
34
- if not filtered_diamonds.empty:
35
- st.write(f"find {len(filtered_diamonds)} diamonds for you.")
36
- st.dataframe(filtered_diamonds)
37
- # Create a scatterplot based on the selected criteria
38
- fig, ax = plt.subplots()
39
- sns.scatterplot(x='carat', y='price', data=filtered_diamonds, ax=ax)
40
- ax.set_title('Prices by Carat')
41
- st.pyplot(fig)
42
- else:
43
- st.write("No diamonds fit you")
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+
6
+ df_diamonds = pd.read_csv('diamonds.csv')
7
+ df_diamonds = df_diamonds.drop(["Unnamed: 0"], axis=1)
8
+
9
+ st.title('Diamond selecting APP')
10
+
11
+ # Users set the price range
12
+ min_price = st.number_input('Input minimum price', min_value=int(df_diamonds['price'].min()), max_value=int(df_diamonds['price'].max()), value=int(df_diamonds['price'].min()))
13
+ max_price = st.number_input('Input maximum price', min_value=min_price, max_value=int(df_diamonds['price'].max()), value=int(df_diamonds['price'].max()))
14
+
15
+ # Select the diamonds
16
+ cuts = st.multiselect('Select cut', df_diamonds['cut'].unique())
17
+ colors = st.multiselect('Select color', df_diamonds['color'].unique())
18
+ clarities = st.multiselect('Select clarity', df_diamonds['clarity'].unique())
19
+
20
+ if st.button('Reset'):
21
+ cuts = []
22
+ colors = []
23
+ clarities = []
24
+ min_price = int(df_diamonds['price'].min())
25
+ max_price = int(df_diamonds['price'].max())
26
+
27
+ # Filter the diamonds
28
+ filtered_diamonds = df_diamonds[(df_diamonds['price'] >= min_price) & (df_diamonds['price'] <= max_price)]
29
+
30
+ if cuts:
31
+ filtered_diamonds = filtered_diamonds[filtered_diamonds['cut'].isin(cuts)]
32
+ if colors:
33
+ filtered_diamonds = filtered_diamonds[filtered_diamonds['color'].isin(colors)]
34
+ if clarities:
35
+ filtered_diamonds = filtered_diamonds[filtered_diamonds['clarity'].isin(clarities)]
36
+
37
+ # Check if there is data to plot
38
+ if not filtered_diamonds.empty:
39
+ # Create a scatterplot based on the selected criteria
40
+ fig, ax = plt.subplots()
41
+ sns.scatterplot(x='carat', y='price', data=filtered_diamonds, ax=ax)
42
+ ax.set_title('Prices by Carat')
43
+ st.pyplot(fig)
44
+ else:
45
+ st.write("No diamonds fit the selected criteria.")
46
+
47
+ # Display a scrollable table with the total information based on the selected criteria
48
+ st.write("Total Information:")
49
+ st.dataframe(filtered_diamonds)