본문 바로가기

택시데이터분석

(빅데이터 처리 분석)뉴욕 택시 데이터를 수집해보자 1탄

반응형

부릉

 


미국 택시데이터를 분석하여 코로나 전 후 택시
유동량을 관찰 분석하는 조그마한 프로젝트를 진행하려고 한다.!

 

 

 

일단 데이터를 다운로드 사이트는 요기 있다..

https://www.nyc.gov/site/tlc/about/tlc-trip-record-data.page

 

TLC Trip Record Data - TLC

TLC Trip Record Data Yellow and green taxi trip records include fields capturing pick-up and drop-off dates/times, pick-up and drop-off locations, trip distances, itemized fares, rate types, payment types, and driver-reported passenger counts. The data use

www.nyc.gov

 

이 데이터는 미국에 뉴욕 택시의 종류마다 유동량 데이터를 제공하는 사이트이며 심지어 무료다..

눈부셔요 미국..

 

 

난 2020~ 2022년 데이터를 모두 수집하여 대용량 처리를 목적을 둔 것이기에 

기존 클릭으로선 시간이 많이 걸리고... 크롤링 스크립트를 만들어서 가져오기로 하자..

 

bs + selenium 조합으로 진행했으며 간단한 로직을 설명하면 

import datetime
import create_log

from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver


# 현재 시각하는 시간 설정
start_time = datetime.datetime.now()

# 로그
log = create_log.log()

option_chrome = webdriver.ChromeOptions()
option_chrome.add_argument('headless')
option_chrome.add_argument("disable-gpu")
option_chrome.add_argument("disable-infobars")
option_chrome.add_argument("--disable-extensions")


# 속도
prefs = {'profile.default_content_setting_values'
         : {'cookies': 2, 'images': 2, 'plugins': 2, 'popups': 2, 'geolocation': 2, 'notifications': 2,
            'auto_select_certificate': 2, 'fullscreen': 2, 'mouselock': 2, 'mixed_script': 2, 'media_stream': 2,
            'media_stream_mic': 2, 'media_stream_camera': 2, 'protocol_handlers': 2, 'ppapi_broker': 2,
            'automatic_downloads': 2, 'midi_sysex': 2, 'push_messaging': 2, 'ssl_cert_decisions': 2,
            'metro_switch_to_desktop': 2, 'protected_media_identifier': 2, 'app_banner': 2, 'site_engagement': 2,
            'durable_storage': 2}
         }

option_chrome.add_experimental_option('prefs', prefs)

# chromedriver_path
web_driver = webdriver.Chrome(ChromeDriverManager().install(), options=option_chrome)


log.info(f"사이트 HTML 수집을 시작합니다.")
class GoogleUtilityDriver:
   def __init__(self, driver=web_driver) -> None:
      self.url = f"https://www.nyc.gov/site/tlc/about/tlc-trip-record-data.page"
      self.driver = driver
   
   def page(self) -> str:
      self.driver.get(self.url)
      return self.driver.page_source

이런 식으로  셀레니움에서 url source를 return 해주고 return 된 html code에 구문을 찾아가는 로직으로 진행하였다..

물론 코드를 다 안올린건 함정 ㅎ.. ㄹㅇㅋㅋ

 

 

결과는..!?

영롱하다

 

저장이 아주 잘된 걸 확인할 수 있다.. 총데이터의 개수를 확인하고자 pandas를 사용 총 데이터 개수를 확인하였는데.. 

?

 

진짜 광기

 

 

 

4억9천만 엌ㅋㅋㅋ




데이터를 수집 했으니.. 어떤걸 분석할지 알아보자.. 다음편에 계속 

 

반응형