<aside> 📌 Task : ✅ (1단계)

import matplotlib.pyplot as plt

plt.figure(figsize=(8, 5))
bars = plt.bar(city_counts['neighbourhood_group'], city_counts['listing_count'])

# 라벨 붙이기
for bar in bars:
    height = bar.get_height()
    plt.text(bar.get_x() + bar.get_width()/2, height + 200, f'{height}', 
             ha='center', va='bottom', fontsize=10, fontweight='bold')

plt.title('대도시별 전체 숙소 수')
plt.xlabel('대도시 (neighbourhood_group)')
plt.ylabel('숙소 수')
plt.tight_layout()
plt.show()

download.png

⇒맨해튼에 가장 많이 분포함.

⇒블루클린도 맨해튼 이랑 거의 비등하게 있음.

import matplotlib.pyplot as plt
import numpy as np

# 지역별 평균 가격 구하기
region_price_stats = df.groupby('neighbourhood_group')['price'].agg(['mean', 'median', 'max', 'count']).sort_values(by='mean')

# 평균값 반올림 (소수점 1자리)
rounded_means = region_price_stats['mean'].round(1)

# 시각화
plt.figure(figsize=(8, 6))
bars = plt.bar(rounded_means.index, rounded_means.values)

# 라벨 추가 (막대 위에 평균 가격 표시)
for bar, value in zip(bars, rounded_means):
    plt.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 5, f'{value}', 
             ha='center', va='bottom', fontsize=10, fontweight='bold')

plt.title('지역별 평균 숙박 가격 (반올림)')
plt.xlabel('지역 (neighbourhood_group)')
plt.ylabel('평균 가격 ($)')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()

download.png

맨해튼은 가장 많은 숙소를 보유하고, 숙박 가격 평균 또한 가장 높음.

import matplotlib.pyplot as plt
import seaborn as sns

# 데이터 준비
roomtype_counts = df.groupby(['neighbourhood_group', 'room_type']).size().reset_index(name='count')

# 시각화
plt.figure(figsize=(10, 6))
ax = sns.barplot(data=roomtype_counts, x='neighbourhood_group', y='count', hue='room_type')

# 막대 위에 값 표시 (굵게, 중앙 정렬)
for container in ax.containers:
    ax.bar_label(container, fmt='%d', label_type='edge', fontsize=10, fontweight='bold')

# 그래프 제목 및 축
plt.title('대도시별 방타입 구성 (숙소 수)', fontsize=14, fontweight='bold')
plt.xlabel('대도시 (neighbourhood_group)', fontsize=12)
plt.ylabel('숙소 수', fontsize=12)
plt.legend(title='Room Type')
plt.tight_layout()
plt.show()

download.png

맨해튼의 평균가격대가 높은 이유는 아파트 형태의 숙소가 많기 때문이다.

⇒ 가격대가 높은 것들을 함부로 제거하면 안 됨.

⇒2번째로 분포 비율이 높은 블루 클린은 개인방이 더 많음.