KevinDHS/Final_Project
0
1import streamlit as st2import pandas as pd3import matplotlib.pyplot as plt4import seaborn as sns5 6# Add CSS style for color theme7st.markdown(8 """9 <style>10 /* Set text color */11 body {12 color: #333333;13 }14 15 /* Set background color */16 .stApp {17 background-color: #659DBd;18 }19 .divider {20 background-color: #000000; /* Black color */21 }22 </style>23 """,24 unsafe_allow_html=True25)26 27def run():28 st.markdown('<h1 style="text-align: center; color: white;">APART HELPER EDA</h1>', unsafe_allow_html=True)29 st.markdown('<p style="text-align: center;">Apart Helper is a product website designed to assist customers in choosing apartments or properties based on their preferences.</p>', unsafe_allow_html=True)30 st.divider()31 32 # Melakukan loading dataset33 data_sebelum = pd.read_csv('properties_data.csv')34 data_sesudah = pd.read_csv('data_setelah_clustering.csv', index_col=0)35 36 st.header('Exploratory Data Analysis Sebelum Cluster', divider='rainbow')37 st.subheader('Top 5 Location By Average Price')38 39 # Calculate the average price for each neighborhood40 avg_price_by_neighborhood = data_sebelum.groupby('neighborhood')['price'].mean()41 42 # Sort the average prices in descending order and select the top 543 top_5_avg_price = avg_price_by_neighborhood.sort_values(ascending=False).head(5)44 45 # Display the top 5 neighborhoods using Streamlit46 st.bar_chart(top_5_avg_price)47 48 st.subheader('Number of Bedrooms',divider='rainbow')49 50 # Group data by 'no_of_bathrooms' and count frequencies51 bathroom_counts = data_sebelum['no_of_bedrooms'].value_counts().sort_index()52 53 # Plot bar chart using Streamlit54 st.bar_chart(bathroom_counts)55 56 st.subheader('Number of Bathrooms',divider='rainbow')57 58 # Group data by 'no_of_bathrooms' and count frequencies59 bathroom_counts = data_sebelum['no_of_bathrooms'].value_counts().sort_index()60 61 # Plot bar chart using Streamlit62 st.bar_chart(bathroom_counts)63 64 65 st.header('Exploratory Data Analysis Setelah Cluster', divider='rainbow')66 # Assuming mean_data is your DataFrame containing the mean prices for each cluster67 mean_data = data_sesudah.groupby('cluster')['price'].mean().reset_index()68 mean_data['cluster'] = mean_data['cluster'].astype(int) # Ensure 'cluster' column is of integer type69 mean_data = mean_data.round(0).astype(int)70 71 # Display the DataFrame in Streamlit72 st.dataframe(mean_data)73 74 st.subheader('Average Price by Cluste',divider='rainbow')75 76 # Assuming mean_data is your DataFrame containing the mean prices for each cluster77 mean_data = data_sesudah.groupby('cluster')['price'].mean().reset_index()78 mean_data['cluster'] = mean_data['cluster'].astype(int) # Ensure 'cluster' column is of integer type79 mean_data = mean_data.round(0).astype(int)80 81 # Plot stacked bar chart82 st.bar_chart(mean_data.set_index('cluster'), use_container_width=True)83 84 st.subheader('Top 5 Location By Average Price Based on Price',divider='rainbow')85 # Filter data for the top 5 neighborhoods86 top_5_avg_price = avg_price_by_neighborhood.sort_values(ascending=False).head(5)87 filtered_data = data_sesudah[data_sesudah['neighborhood'].isin(top_5_avg_price.index)]88 89 # Group by 'neighborhood' and 'cluster', then calculate the average price for each group90 avg_price_by_neighborhood_cluster = filtered_data.groupby(['neighborhood', 'cluster'])['price'].mean().unstack()91 92 # Plot stacked bar chart for top 5 neighborhoods93 st.bar_chart(avg_price_by_neighborhood_cluster, use_container_width=True) 94 95 96 st.subheader('Number of Bedrooms Based on Cluster',divider='rainbow')97 # Group data by 'no_of_bathrooms' and 'cluster', then count frequencies98 bathroom_cluster_counts = data_sesudah.groupby(['no_of_bedrooms', 'cluster']).size().unstack(fill_value=0)99 100 # Plot stacked bar chart101 st.bar_chart(bathroom_cluster_counts, use_container_width=True)102 103 st.subheader('Number of Bathrooms Based on Cluster',divider='rainbow')104 # Group data by 'no_of_bathrooms' and 'cluster', then count frequencies105 bathroom_cluster_counts = data_sesudah.groupby(['no_of_bathrooms', 'cluster']).size().unstack(fill_value=0)106 107 # Plot stacked bar chart108 st.bar_chart(bathroom_cluster_counts, use_container_width=True)109 110if __name__ == '__main__':111 run()112 