Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
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 |
-
|
7 |
-
|
8 |
-
|
9 |
-
st.title('Diamond APP
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
st.
|
18 |
-
st.
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
filtered_diamonds =
|
32 |
-
|
33 |
-
|
34 |
-
if
|
35 |
-
|
36 |
-
|
37 |
-
#
|
38 |
-
|
39 |
-
|
40 |
-
ax.
|
41 |
-
|
42 |
-
|
43 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|