File size: 2,320 Bytes
b1e4a2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b4731b7
b1e4a2b
 
 
 
 
b4731b7
b1e4a2b
 
1
2
3
4
5
6
7
8
9
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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)