본문 바로가기

분류 전체보기162

예제 2. 위키백과 문서 정보 가져오기 01. 위키백과에 여명의 눈동자 검색한다. 02. 크롬 개발자 도구 03. 원하는 데이터의 위치를 파악한다. command shift c 04. 주소 가져온다. urllib.parse.quote()는 urllib에 내장된 포맷팅 함수. 이 과정에서 주의깊게 봐야 할 점은, ✔︎ 위키백과에서 주소 복사해올 시 https://ko.wikipedia.org/wiki/%EC%97%AC%EB%AA%85%EC%9D%98_%EB%88%88%EB%8F%99%EC%9E%90 이렇게 뒷부분이 정리되지 않은 채 나열되어 있다. => google에 url decode 검색하면 나오는 decoding 해주는 사이트에 주소 복붙 후 정리된 주소를 사용해줘야한다. code에는 뒷부분을 {search_words}를 사용해 날려주고 .. 2022. 11. 20.
예제1-2 네이버금융 !pip install requests find, find_all select, select_one find, select_one : 단일선택 select, find_all : 다중선택 ``` import requests # = from urllib.request.Request 위와 같다. from bs4 import BeautifulSoup ``` url = "https://finance.naver.com/marketindex/" response = requests.get(url) # get 대신 post 가능하다. $ response 입력하면 200 상태 코드 출력된다. soup = BeautifulSoup(response.text, "html.parser") print(soup.prettify()).. 2022. 11. 18.
예제1-1. 네이버 금융 ● import ``` from urllib.request import urlopen from bs4 import BeautifulSoup ``` ● 페이지 불러오기 ``` url = "https://finance.naver.com/marketindex/" page = urlopen(url) soup = BeautifulSoup(page, "html.parser") print(soup.prettify()) ``` 보통 page 변수 말고 response나 res 더 자주 쓰임. response.status 출력하면 값이 제대로 불러와졌는지 숫자로 확인 가능. https://ko.wikipedia.org/wiki/HTTP_상태_코드 ● 환율값 불러오기 ``` # 1 soup.find_all("span", .. 2022. 11. 17.
Beautiful Soup Basic ● install - conda install -c anaconda beautifulsoup4 - pip install beautifulsoup4 ● import ``` from bs4 import BeautifulSoup ``` ● open ``` page = open("../data/-", "r").read() soup=BeautifulSoup(page, "html.parser") print(soup.prettify()) ``` prettify() 써줄 시 , 들여쓰기 된 상태의 가독성 좋은 html로 불러와줌 ● tag 확인 ``` # head 태그 확인 soup.head # body 태그 확인 soup.body # p 태그 확인 / 가장 처음에 입력된 p 태그만 확인 가능 soup.p soup.f.. 2022. 11. 17.
Folium Icon Site Folium Icon 01. fa type 02. glyphicon type ✔️ folium icon : 가끔 표시 안되면 prefix="fa" 값 설정 . option 확인. 모든 아이콘이 나타나는건 아니다. https://fontawesome.com/search?m=free&o=r Font Awesome The internet's icon library + toolkit. Used by millions of designers, devs, & content creators. Open-source. Always free. Always awesome. fontawesome.com ✔️glyphicon : 애초에 입력시에 glyphicon glyphicon-cloud 기재 해주나, prefix="glyph.. 2022. 11. 16.
Examples 05. Anscombe data 05. Anscombe data lmplot anscombe = sns.load_dataset("anscombe") anscombe.tail() 2022. 11. 16.
Example 04.Iris data 04. Iris data iris = sns.load_dataset("iris") iris.tail() pairplot sns.set_style("ticks") unique로 species 확인 후 hue option으로 가독성 + 종 나누기 원하는 columns만 지정하여 pairplot 생성도 가능 2022. 11. 15.
Example 03.flight data 03.Flight data heatmap pivot_table(index, columns, values) flights = sns.load_dataset("flights") flights.head() flights.info() # pivot # index, columns, values flights = flights.pivot(index = "month" , columns = "year", values = "passengers") flights.head() heatmap annot : heatmap 위 데이터 숫자 표현 fmt : d, f 등 정수 , 실수 표현 가능 cmap : color 바꿀 수 있음 2022. 11. 15.
Example 02. seaborn tips data 02. Seaborn tips data - boxplot - swarmplot - lmplot tips = sns.load_dataset("tips") tips tips.info() x=tips["total bill"] 박스 가운데 선은 평균값 x="day", y="total_bill", data="tips" boxplot hue palette option hue ="smoker" : smoker yes, no 판단 palette="Set3' : 색상 결정. Set1 ~ 3까지 있음. swarmplot color : 0(검정) ~ 1(흰) 색상 표현 boxplot + swarmplot lmplot : total_bill과 tip의 상관관계 파악 여기서, size는 height로 표기됨. ▵데이터 구분되어.. 2022. 11. 14.