Spaces:
Sleeping
Sleeping
File size: 1,757 Bytes
6f00d18 |
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 |
import streamlit as st
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
############### PAGE SETUP ########################
###################################################
st.set_page_config(layout="wide")
st.header("Smiple Charts")
############ HELPER FUNCTIONS #####################
###################################################
@st.cache_data
def load_data():
df = pd.read_csv('data/ny-vs-sf-houses.csv')
return df
def display_data(n=5):
#Randomize the data
display_df = df.sample(n=n)
st.dataframe(display_df)
def plot_streamlit_scatter_chart():
st.scatter_chart(df, x='price', y='elevation', color='city', size='sqft')
def plot_static_seaborn_chart():
fig, ax = plt.subplots(figsize = (50,30))
_ = sns.histplot(df, x='elevation', hue='city', multiple='stack')
st.pyplot(fig)
################## PAGE LAYOUT ###################
###################################################
df = load_data()
col1, col2 = st.columns([1, 3])
## COL1 WILL HOLD OUR FILTERS
with col1:
## FILTERS
selected_cities = st.multiselect(
'Select which states to compare.',
['SF', 'NY'],
default=['SF', 'NY'] )
# Use selected cities to filter the dataframe
df = df[df['city'].isin(selected_cities)]
# Create a price filter
price_filter = st.slider(
"Filter for only prices above",
min_value = df.price.min(),
max_value = df.price.max(),
step=100000
)
# filter for only prices greater than price_filter value.
df = df[df['price'] >= price_filter]
## COL2 WILL HOLD OUR CHARTS
with col2:
display_data()
plot_streamlit_scatter_chart()
plot_static_seaborn_chart()
|