Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -3,47 +3,41 @@ import pandas as pd
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import seaborn as sns
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
st.title('Diamond
|
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 |
-
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 |
-
|
|
|
|
|
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
|
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)
|
|
|
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. Noted by Dimitri')
|
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")
|
|
|
|
|
|
|
|