import streamlit as st st.set_page_config(layout="wide") import pandas as pd import plotly.express as px # titles st.sidebar.markdown("## HDB Resale Prices") st.sidebar.markdown("Flat Options") # read data @st.cache def load_data(): return pd.read_csv("data.csv") df = load_data() # setup UI town_options = list(df["town"].unique()) town_options.sort() town_options = ["ALL"] + town_options town = st.sidebar.selectbox(label="Town", options=town_options) if town != "ALL": df = df[df['town']==town] flat_type_options = list(df["flat_type"].unique()) flat_type_options.sort() flat_type_options = ["ALL"] + flat_type_options flat_type = st.sidebar.selectbox(label="Flat Type", options=flat_type_options) if flat_type != "ALL": df = df[df['flat_type']==flat_type] flat_model_options = list(df["flat_model"].unique()) flat_model_options.sort() flat_model_options = ["ALL"] + flat_model_options flat_model = st.sidebar.selectbox(label="Flat Model", options=flat_model_options) if flat_model != "ALL": df = df[df['flat_model']==flat_model] storey_options = list(df["storey_range"].unique()) storey_options.sort() storey_options = ["ALL"] + storey_options storey_range = st.sidebar.selectbox(label="Storey Range", options=storey_options) if storey_range != "ALL": df = df[df['storey_range']==storey_range] floor_area_options = list(df["floor_area_sqm"].unique()) floor_area_options.sort() floor_area_options = ["ALL"] + floor_area_options floor_area = st.sidebar.selectbox(label="Floor Area", options=floor_area_options) if floor_area != "ALL": df = df[df['floor_area_sqm']==floor_area] #df = df.drop(labels=["town", "flat_type", "storey_range", "floor_area_sqm"], axis="columns") df = df.drop(labels=["town", ], axis="columns") df = df.sort_values(by="month", ascending=False) #df["floor_area_sqm"] = df["floor_area_sqm"].astype("int") df["resale_price"] = df["resale_price"].astype("int") st.markdown("#### Selected Data") st.dataframe(data=df) fig = px.box(df, x="month", y="resale_price", title='Visualization: Resale Price over time') st.plotly_chart(fig, use_container_width=True)