Spaces:
Runtime error
Runtime error
Download src/eda.py from aristrisnawan/milestone-2: direct link, hf CLI and curl.
- Browser
- Download file 2.95 kB
-
https://huggingface.co/spaces/aristrisnawan/milestone-2/resolve/main/src/eda.py
- Command line
-
hf download hf://spaces/aristrisnawan/milestone-2/src/eda.py
-
curl -L -o eda.py https://huggingface.co/spaces/aristrisnawan/milestone-2/resolve/main/src/eda.py
2.95 kB
| import streamlit as st | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| def category_property(sqft): | |
| if sqft <= 1000: | |
| return 'Rumah Standar' | |
| elif sqft <= 2000: | |
| return 'Rumah Luas' | |
| elif sqft <= 4000: | |
| return 'Rumah Sangat Luas' | |
| else: | |
| return 'Rumah Mewah' | |
| # data['HOUSE_CATEGORY'] = data['PROPERTYSQFT'].apply(category_property) | |
| def run(): | |
| st.subheader('Exploratory Data Analysis (EDA)') | |
| st.write('Exploratory Data Analysis (EDA) dari dataset New York Housing Market') | |
| data = pd.read_csv('./src/csv/NY-House-Dataset.csv') | |
| st.dataframe(data) | |
| # menampilkan sublocatity | |
| st.write('### Top 5 jumlah rumah terbanyak') | |
| jumlah = data['SUBLOCALITY'].value_counts().head() | |
| fig = plt.figure(figsize=(12,6)) | |
| jumlah.plot(kind='bar') | |
| plt.title('Jumlah Kemunculan Setiap Sublocality') | |
| plt.xlabel('Sublocality') | |
| plt.ylabel('Jumlah') | |
| plt.xticks(rotation=45, ha='right') | |
| plt.tight_layout() | |
| st.pyplot(fig) | |
| #menampilkan harga rumah termahal dan berdasrkan lokasi | |
| st.write('### Top 10 harga rumah termahal berdasarkan state') | |
| higher = data.groupby('STATE')['PRICE'].max().reset_index().head(10) | |
| higher_sorted = higher.sort_values(by='PRICE', ascending=False) | |
| fig = plt.figure(figsize=(12,6)) | |
| sns.barplot(x='STATE', y='PRICE',data=higher_sorted) | |
| plt.title('10 Harga Rumah Tertinggi') | |
| plt.xlabel('State') | |
| plt.ylabel('Price') | |
| plt.xticks(rotation=45, ha='right') | |
| plt.tight_layout() | |
| st.pyplot(fig) | |
| #menampilkan harga rumah termahal dan berdasrkan lokasi | |
| st.write('### List 10 harga rumah termurah berdasarkan state') | |
| lower = data.groupby('STATE')['PRICE'].min().reset_index().head(10) | |
| lower_sorted = lower.sort_values(by='PRICE', ascending=True) | |
| fig = plt.figure(figsize=(12,6)) | |
| sns.barplot(x='STATE', y='PRICE',data=lower_sorted) | |
| plt.title('10 Harga Rumah Tertinggi') | |
| plt.xlabel('State') | |
| plt.ylabel('Price') | |
| plt.xticks(rotation=45, ha='right') | |
| plt.tight_layout() | |
| st.pyplot(fig) | |
| st.write('### Distribusi Luas Rumah (Property Sqft)') | |
| fig = plt.figure(figsize=(12,6)) | |
| sns.histplot(data['PROPERTYSQFT'], bins=50) | |
| plt.title('Distribusi Luas Rumah (Property Sqft)') | |
| plt.xlabel('Property Sqft') | |
| plt.ylabel('Jumlah Rumah') | |
| st.pyplot(fig) | |
| # Presentasi kategori rumah | |
| st.write('### Presentasi Kategori Rumah berdasarkan PROPERTYSQFT') | |
| data['HOUSE_CATEGORY'] = data['PROPERTYSQFT'].apply(category_property) | |
| category = data['HOUSE_CATEGORY'].value_counts() | |
| fig = plt.figure(figsize=(10,6)) | |
| plt.pie(category, labels=category.index, autopct='%1.1f%%', startangle=90) | |
| plt.title('Presentasi Kategori Rumah') | |
| plt.tight_layout() | |
| st.pyplot(fig) | |
| if __name__ == '__main__': | |
| run() |