[AI SCHOOL 5기] 웹 크롤링 실습 - 웹 스크래핑 기본

BeautifulSoup Library 1 2 from bs4 import BeautifulSoup from urllib.request import urlopen 단어의 검색 결과 출력 다음 어학사전 URL 불러오기 1 2 3 4 5 6 # 찾는 단어 입력 word = 'happiness' url = f'https://alldic.daum.net/search.do?q={word}' web = urlopen(url) web_page = BeautifulSoup(web, 'html.parser') 찾는 단어 출력 1 2 text_search = web_page.find('span', {'class': 'txt_emph1'}) print(f'찾는 단어: {text_search.get_text()}') 단어의 뜻 출력 1 2 3 4 list_search = web_page.find('ul', {'class': 'list_search'}) list_text = list_search....

March 25, 2022 · 2 min · 358 words · minyeamer

[AI SCHOOL 5기] 웹 크롤링

Web Crawling vs Web Scraping Web Crawling: Bot이 web을 link를 통해 돌아다니는 것 Web Scraping: Webpage에서 원하는 자료를 긇어오는 것 HTML Tags Tag’s Name: html, head, body, p, span, li, ol, ul, div Tag’s Attribute: class, id, style, href, src The Process of Web Scraping URL 분석 (query 종류 등) URL 구성 HTTP Response 얻기 (urlopen(URL) or request.get(URL).content) HTTP source 얻기 (BeautifulSoup(HTTP Response, 'html.parser')) HTML Tag 꺼내기 (.find('tag_name', {'attr_name':'attr_value'})) Tag로부터 텍스트 혹은 Attribute values 꺼내기 (Tag....

March 25, 2022 · 2 min · 232 words · minyeamer

[AI SCHOOL 5기] 데이터 분석 실습 - 데이터 시각화

Visualization Libraries Plotly Altair Bokeh (Website Graph) @ https://j.mp/30772sU Data Chart Types Numeric: 숫자 자체에 의미가 있음 (온도 등), 연속형 Categoric: 숫자 너머에 의미가 있음 (성별, 강아지 품종 등), 불연속형 @ https://goo.gl/ErLHCY @ http://j.mp/2JcEENe GeoJSON Data 1 2 3 4 5 6 import json # 한국의 지도 데이터 참조 # @ https://github.com/southkorea/southkorea-maps geo_path = 'skorea_municipalities_geo_simple.json' geo_str = json.load(open(geo_path, encoding='utf-8')) JSON(Javascript Object Notation): 데이터 교환을 위한 표준 포맷 GeoJSON: 지도 데이터 포맷 json....

March 24, 2022 · 4 min · 651 words · minyeamer

[AI SCHOOL 5기] 데이터 분석 실습 - 데이터 탐색

Visualization Library 1 2 3 import seaborn as sns sns.heatmap(gu_df[]) Visualization Issues 한글 데이터 표시 오류 서로 다른 자릿수로 구성된 열에 동일한 스케일 적용 시각화된 테이블 형태의 비직관성 문제 인구수가 고려되지 않은 부정확한 데이터 한글 데이터 시각화 1 2 3 4 5 6 7 8 matplotlib inline # Windows font_name = font_manager.FontProperties(fname="C:/~/malgun.ttf").get_name() rc('font', family=font_name) # Mac rc('font', family='AppleGothic') Feature Scaling/Normalization Min-Max Algorithm 열에 대한 최솟값(min)을 0, 열에 대한 최댓값(max)를 1로 맞춤 기존 열을 old_x, 새로운 열을 new_x라 할 때,...

March 23, 2022 · 2 min · 268 words · minyeamer

[AI SCHOOL 5기] 데이터 분석 실습 - 데이터 분석

Practice Data 서울시 범죄현황 통계자료 범죄별로 검거율 계산 1 2 3 4 5 6 7 # gu_df는 실습 자료에 서울시 경찰청의 소속 구 데이터를 추가한 DataFrame gu_df['강간검거율'] = gu_df['강간(검거)']/gu_df['강간(발생)']*100 gu_df['강도검거율'] = gu_df['강도(검거)']/gu_df['강도(발생)']*100 gu_df['살인검거율'] = gu_df['살인(검거)']/gu_df['살인(발생)']*100 gu_df['절도검거율'] = gu_df['절도(검거)']/gu_df['절도(발생)']*100 gu_df['폭력검거율'] = gu_df['폭력(검거)']/gu_df['폭력(발생)']*100 gu_df['검거율'] = gu_df['소계(검거)']/gu_df['소계(발생)']*100 해당 계산법의 문제: 이전 연도에 발생한 사건이 많이 검거될 경우 검거율이 100%를 초과 발생 건수가 0인 경우 검거율에 결측치(N/A)가 발생 초과된 검거율을 최댓값으로 조정: 1 2 # 검거율에 해당되는 열의 집합 columns columns = ['강간검거율', '강도검거율', '살인검거율', '절도검거율', '폭력검거율'] 모든 행에 대해 반복문 실행 1 2 3 4 for row_index, row in gu_df_rate....

March 23, 2022 · 2 min · 289 words · minyeamer