카테고리 없음

[250418] 심화 프로젝트 1일차

jeonieee 2025. 4. 18. 21:21

모든 열을 보고자 할때: pd.set_option('display.max_columns',None)

모든 행을 보고자 할때: pd.set_option('display.max_rows',None)

원래대로 돌리기: pd.options.display.max_columns = 20

                          pd.options.display.max_rows = 60 

 

- 주제 : airbnb 

 

- 데이터 항목 설명 (한국어)

  • id (integer): Airbnb 숙소의 고유 식별자
  • listing_url (text): 숙소의 URL
  • scrape_id (bigint): Airbnb "스크래핑"에서 이 숙소가 포함된 스크랩 ID
  • last_scraped (datetime): 이 숙소 정보가 마지막으로 스크래핑된 날짜 및 시간 (UTC)
  • source (text): 정보 출처 ("neighbourhood search"는 동네 검색을 통해, "previous scrape"은 이전 스크래핑에서 확인된 정보)
  • name (text): 숙소의 이름
  • description (text): 숙소에 대한 상세 설명
  • neighborhood_overview (text): 호스트가 설명하는 숙소가 위치한 동네 개요
  • picture_url (text): 숙소 사진의 URL (Airbnb에서 제공하는 일반 크기 사진)
  • host_id (integer): 호스트의 고유 식별자
  • host_url (text): 호스트의 Airbnb 페이지 URL
  • host_name (text): 호스트 이름 (보통 첫 이름만)
  • host_since (date): 호스트가 Airbnb에 가입한 날짜 (게스트로 가입한 날짜일 수도 있음)
  • host_location (text): 호스트가 자주 사용하는 지역이나 자택 위치 (자기 보고)
  • host_about (text): 호스트에 대한 설명
  • host_response_time: 호스트가 메시지에 응답하는 평균 시간
  • host_response_rate: 호스트의 응답 비율
  • host_acceptance_rate: 호스트의 예약 요청 수락 비율
  • host_is_superhost (boolean): 호스트가 슈퍼호스트인지 여부 (t=슈퍼호스트, f=슈퍼호스트 아님)
  • host_thumbnail_url (text): 호스트의 프로필 사진 썸네일 URL
  • host_picture_url (text): 호스트의 프로필 사진 URL
  • host_neighbourhood (text): 호스트가 위치한 동네
  • host_listings_count (text): 호스트가 보유한 숙소 수 (Airbnb 계산)
  • host_total_listings_count (text): 호스트가 보유한 전체 숙소 수 (Airbnb 계산)
  • host_verifications: 호스트가 인증한 항목들 (예: 이메일, 전화번호, 신분증 등)
  • host_has_profile_pic (boolean): 호스트의 프로필 사진 유무 (t=있음, f=없음)
  • host_identity_verified (boolean): 호스트의 신원 인증 여부 (t=인증됨, f=인증되지 않음)
  • neighbourhood (text): 숙소가 위치한 동네
  • neighbourhood_cleansed (text): 숙소가 위치한 동네 이름 (정리된 버전)
  • neighbourhood_group_cleansed (text): 숙소가 속한 동네 그룹 (정리된 버전)
  • latitude (numeric): 숙소의 위도 (WGS84 기준)
  • longitude (numeric): 숙소의 경도 (WGS84 기준)
  • property_type (text): 숙소의 유형 (예: 아파트, 주택 등)
  • room_type (text): 숙소의 방 유형
  • Entire home/apt: 전체 숙소
  • Private room: 개인 방
  • Shared room: 공유 방
  • accommodates (integer): 숙소가 수용할 수 있는 최대 인원 수
  • bathrooms (numeric): 숙소의 욕실 수
  • bathrooms_text (string): 숙소에 있는 욕실에 대한 설명 (예: "1 shared bath"는 공용 욕실)
  • bedrooms (integer): 침실 수
  • beds (integer): 침대 수
  • amenities (json): 숙소에서 제공하는 편의시설 목록
  • price (currency): 숙소의 1박 가격 (현지 통화)
  • minimum_nights (integer): 예약 시 최소 숙박 일수
  • maximum_nights (integer): 예약 시 최대 숙박 일수
  • minimum_minimum_nights (integer): 캘린더에서 가장 작은 최소 숙박 일수
  • maximum_minimum_nights (integer): 캘린더에서 가장 큰 최소 숙박 일수
  • minimum_maximum_nights (integer): 캘린더에서 가장 작은 최대 숙박 일수
  • maximum_maximum_nights (integer): 캘린더에서 가장 큰 최대 숙박 일수
  • minimum_nights_avg_ntm (numeric): 평균 최소 숙박 일수 (365일 기준)
  • maximum_nights_avg_ntm (numeric): 평균 최대 숙박 일수 (365일 기준)
  • calendar_updated (date): 숙소 캘린더 업데이트 날짜
  • has_availability (boolean): 예약 가능 여부 (t=가능, f=불가)
    • 범주형 변수 (Categorical)
      • listing_url, source, name, description, neighborhood_overview, picture_url
      • host_url, host_name, host_location, host_about, host_thumbnail_url, host_picture_url, host_neighbourhood
      • neighbourhood, neighbourhood_cleansed, neighbourhood_group_cleansed
      • property_type, room_type
      • bathrooms_text, amenities
      • host_response_time, host_verifications
      • has_availability, host_is_superhost, host_has_profile_pic, host_identity_verified
      🔢 수치형 변수 (Numerical)
      • id, scrape_id, host_id
      • latitude, longitude
      • accommodates, bathrooms, bedrooms, beds
      • price, minimum_nights, maximum_nights
      • minimum_minimum_nights, maximum_minimum_nights, minimum_maximum_nights, maximum_maximum_nights
      • minimum_nights_avg_ntm, maximum_nights_avg_ntm
      • host_listings_count, host_total_listings_count
      • host_response_rate, host_acceptance_rate코드 진행
  • 코드 진행
import pandas as pd
import numpy as np
from google.colab import drive
from datetime import datetime

airbnb = pd.read_csv("/2025_Airbnb_NYC_listings.csv")
airbnb = airbnb.drop('calendar_updated', axis=1) # 데이터 전체 없는 컬럼 삭제

df = [['neighbourhood_group_cleansed', 'property_type', 'room_type', 'accommodates', 'bathrooms', 'bathrooms_text', 'bedrooms', 'beds', 'amenities', 'price', 'minimum_nights', 'maximum_nights', 'number_of_reviews', 'number_of_reviews_l30d', 'review_scores_rating']]

# bathrooms_text가 shared면 0, 아니면 1
# airbnb_cleaned['bathrooms_text'] = airbnb_cleaned['bathrooms_text'].apply(lambda x: 0 if 'shared' in x else 1)
airbnb_cleaned['bathrooms_text'] = airbnb_cleaned['bathrooms_text'].apply(lambda x: 0 if isinstance(x, str) and 'shared' in x else 1)

import pandas as pd

# airbnb_cleaned가 DataFrame이라고 가정

# 각 숙소의 편의시설 개수를 계산하여 'amenities' 열에 저장
for index in airbnb_cleaned.index:
    amenities_string = airbnb_cleaned.loc[index, 'amenities']
    amenities_list = amenities_string[1:-1].replace('"', '').split(',')
    airbnb_cleaned.loc[index, 'amenities'] = len(amenities_list)  # 편의시설 개수로 값을 변경
    
# 가격에서 $표시 삭제 및 숫자형으로 변환
airbnb_cleaned['price'] = airbnb_cleaned['price'].astype(str).str.lstrip('$').str.replace(',', '').astype(float)    

# 결과
airbnb_cleaned.head()

 

내가 나머지 프로젝트도 잘 할수 있을까...

혼돈의 Q&A....