Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
# read the dataset | |
df = pd.read_csv('diamonds.csv') | |
st.title('Diamond APP sorting festivity') | |
df = df.drop(["Unnamed: 0"], axis=1) | |
#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. | |
df = df.drop(df[df["x"]==0].index) | |
df = df.drop(df[df["y"]==0].index) | |
df = df.drop(df[df["z"]==0].index) | |
st.image('diamonds.jpg') | |
st.write(f"the price range is {326} to {18823}") | |
# users set the price range | |
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())) | |
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())) | |
#users select | |
selected_cuts = st.multiselect('choosing cut', df['cut'].unique()) | |
selected_cuts = st.multiselect('choosing color', df['color'].unique()) | |
selected_cuts = st.multiselect('choosing clarity', df['clarity'].unique()) | |
selected_cuts = st.multiselect('choosing carat', df['carat'].unique()) | |
# select the diamonds | |
filtered_diamonds = df[(df['price'] >= min_price) & (df['price'] <= max_price)] | |
# show the results | |
if not filtered_diamonds.empty: | |
st.write(f"find {len(filtered_diamonds)} diamonds for you.") | |
st.dataframe(filtered_diamonds) | |
# Create a scatterplot based on the selected criteria | |
fig, ax = plt.subplots() | |
sns.scatterplot(x='carat', y='price', data=filtered_diamonds, ax=ax) | |
ax.set_title('Prices by Carat') | |
st.pyplot(fig) | |
else: | |
st.write("No diamonds fit you") |