Create a streamlit application with general metrics of the current economic state of multi-family real-estate, if their is public data for it, include things like current listing for apartments based on region, and the ability to see pictures of said listings.
To upload files, please first save the app
import streamlit as st
import pandas as pd
import plotly.express as px
from PIL import Image
import requests
import io
import json
st.set_page_config(page_title="Real Estate Metrics", layout="wide")
# NOTE: Using corsproxy.io because we're in a WASM environment. If running locally,
# you can remove the corsproxy.io prefix.
ZILLOW_DATA_URL = "https://corsproxy.io/?https://files.zillowstatic.com/research/public_csvs/zhvi/Metro_zhvi_uc_sfrcondo_tier_0.33_0.67_sm_sa_month.csv"
def load_zillow_data():
try:
df = pd.read_csv(ZILLOW_DATA_URL)
# Melt the dataframe to convert date columns to rows
id_vars = [col for col in df.columns if not col.startswith('20')]
df_melted = df.melt(id_vars=id_vars, var_name='Date', value_name='Price')
df_melted['Date'] = pd.to_datetime(df_melted['Date'])
return df_melted
except Exception as e:
st.error(f"Error loading Zillow data: {str(e)}")
return None
def main():
st.title("Multi-Family Real Estate Market Analysis")
# Sidebar filters
st.sidebar.header("Filters")
# Load data
df = load_zillow_data()
if df is not None:
# Get unique regions
regions = sorted(df['RegionName'].unique())
selected_region = st.sidebar.selectbox("Select Region", regions)
# Create two columns for the layout
col1, col2 = st.columns([2, 1])
with col1:
st.subheader("Price Trends")
# Filter data for selected region
region_data = df[df['RegionName'] == selected_region]
# Create price trend chart
fig = px.line(region_data,
x='Date',
y='Price',
title=f'Price Trends in {selected_region}')
st.plotly_chart(fig, use_container_width=True)
# Calculate key metrics
latest_price = region_data.iloc[-1]['Price']
yoy_change = ((latest_price - region_data.iloc[-13]['Price']) /
region_data.iloc[-13]['Price'] * 100)
# Display metrics
st.metric("Current Average Price", f"${latest_price:,.2f}")
st.metric("Year-over-Year Change", f"{yoy_change:.1f}%")
with col2:
st.subheader("Market Statistics")
# Regional Stats
st.write("Regional Statistics")
stats_df = df[df['RegionName'] == selected_region].describe()
st.dataframe(stats_df)
# Show sample listing disclaimer
st.info("""
Note: Due to data availability limitations, we're showing aggregated
market data from Zillow's Home Value Index. For actual listings and
photos, please visit real estate websites like Zillow, Redfin, or
local real estate agencies.
""")
else:
st.error("Unable to load real estate data. Please try again later.")
# Additional Resources
st.subheader("Additional Resources")
st.markdown("""
For more detailed information about specific properties and current listings, visit:
- [Zillow](https://www.zillow.com)
- [Redfin](https://www.redfin.com)
- [Apartments.com](https://www.apartments.com)
""")
if __name__ == "__main__":
main()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?