본문 바로가기

반응형

Data handling

(31)
[matplotlib] 새창에서 plt.show()보기, 3d 그래프 회전 시키면서 보기 pip install Pyqt5를 한다. import matplotlib matplotlib.use('Qt5Agg')
[numpy] 이미지 채널 축 변경 배치 사이즈가 0번째 축이라고 가정했을 때 (5, 256, 256, 3) 이라는 이미지가 있고 (B, W, H, C) 이를 (5, 3, 256, 256) 차원으로 변경하려면 np.rollaxis(3, 1) 3번 축을 1번 축까지 굴림.
대용량 numpy 파일 text로 쓰기 대용량 numpy 파일 읽고 text로 저장하기¶ 파일 로드 하는 함수¶ In [ ]: def load_files(filepath): return np.loadtxt(filepath, skiprows=1) .npy 파일이 각각 3GB 이상¶ In [ ]: files = ['data/200805 EDC3-1 re_group1_densified_point_cloud_part_0_r.txt.npy', 'data/200805 EDC3-1 re_group1_densified_point_cloud_part_1_r.txt.npy'] ss = [] for file in files: ss.append(np.load(file)) np.savetxt를 이용하여 저장¶ In [ ]: np.save..
[selenium] python, 구글 이미지 크롤링하기 (원본화질, 고화질) 전체코드 from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import TimeoutException from selenium import webdriver from selenium.webdriver.common.keys import Keys import os options = webdriver.ChromeOptions() options.add_argument('headless') options.add_ar..
Pandas error, csv를 읽고 쓸 때 발생하는 유니코드 에러 오류 Pandas에서 csv를 읽고 쓸때 발생하는 에러 UnicodeEncodeError: 'ascii' codec can't encode characters ... print(data.head())라고하면 출력이 안된다. 무슨 문제일까... 작동하지 않는 해결법들 1. 저장할 때 애초에 encoding='utf-8-sig'으로 저장하기. 시도했으나 안됨 df.to_csv('blarblar.csv', encoding='utf-8-sig') stackoverflow.com/questions/44630798/pandas-ascii-codec-cant-encode-character-in-position-ordinal-not-in-range-whi Pandas: ascii codec cant encode cha..
DevToolsActivePort file doesn't exist error 해결법 크롤링 에러 간단하게 해결하는 방법. 에러 WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) 해결법 크롬 옵션 추가 ( headless, no-sandbox 필수) from selenium import webdriver chrome_options = web..
[selenium] js 동적 페이지 크롤링 하기 (주로 댓글) iframe, #document 해결 문제점 특정 사이트의 댓글을 크롤링할때 문제가 발생한다. selenium을 써도 해결이 안 된다. iframe, #document로 구성된 부분에 댓글이 들어가 있다. 문제는 이 안쪽 부분은 접근이 불가능하다는 것이다. 그러면 어떻게 해야할까? 해결책을 알게됐다. iframe 내부에 있는 src 링크로 다시 들어간다. 거기서 selenium 크롤링을 다시 진행하면 된다. 새롭게 html, body 등이 구성되고 element에 접근이 가능한 걸 볼 수 있다. 핵심은 driver.get으로 iframe 내부 링크에 접속하는 것이다. 3 시간 삽질 결과 공유 끝 번외로 마약베개 리뷰 크롤링 예제를 공유한다. from selenium import webdriver import time options = web..
[scrapy] 403 error 발생시 대처법 403 error는 크롤링을 막아놓은 사이트에서 크롤링시 발생하는 에러이다. "2021-02-09 23:27:33 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response : HTTP status code is not handled or not allowed" 해결법은 간단하다. setting.py를 열고 USER_AGENT 부분을 아래와 같이 수정한다. 이후 잘 크롤링 된다. 200 USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36' sangaline.com/po..

728x90
반응형