본문 바로가기
반응형

전체 글123

[python] 데이터 전처리 정규식을 사용한 Cleansing함수 import re def cleansing(text): pattern = '(\[a-zA-Z0-9\_.+-\]+@\[a-zA-Z0-9-\]+.\[a-zA-Z0-9-.\]+)' # e-mail 주소 제거 text = re.sub(pattern=pattern,repl=' ',string=text) pattern = '(http|ftp|https)://(?:[-\w.]|(?:\da-fA-F]{2}))+' # url 제거 text = re.sub(pattern=pattern,repl=' ',string=text) pattern = '([ㄱ-ㅎㅏ-ㅣ])+' # 한글 자음, 모음 제거 text = re.sub(pattern=pattern,repl=' ',string=text) pattern = ']*>' # htm.. 2020. 3. 18.
집계 쿼리 grouping set, rollup, cube select brand , segment , sum(quantity) from sales group by brand, segment union all select brand , null , sum(quantity) from sales group by brand --, segment; union all select null , segment , sum(quantity) from sales group by segment --brand, ; union all select null ,null ,sum(quantity) from sales ; select brand , segment from sales group by grouping sets ( (BRAND, SEGMENT) ,brand ,SEGMENT ,() .. 2020. 2. 18.
[전처리] python 데이터 추출 (기본) 사용 Tool : jupyter notebook 0. 라이브러리 임포트 import pandas as pd # pandas 데이터 프레임 라이브러리 가지고옴 import numpy as np 1. 데이터 추출하기 (경로를 모를때는 pwd로 현재 경로를 볼 수 있다.) reserve_tb = pd.read_csv('data/reserve.csv', encoding = 'utf-8') # 인코딩 설정. reserve_tb.head() # reserve_tb가 잘 들어왔는지 5 행말 추출한다. reserve_tb.shape # reserve_tb의 행과 열의 수를 볼 수 있다. 전체적인 shape 확인 가능 # numpy함수의 기능 # head(N) : 상위에서 추출할 숫자를 설정할 수 잇다. 2. 추출할 열.. 2020. 2. 13.
[전처리] R로 데이터 추출하기 (기본) 1. 데이터 읽기 reserve_tb fileEncoding : 읽어올 파일의 인코딩 설정 > header : 헤더 유무 설정 > stringsAsFactors : False로 지정하여 문자열을 번주형으로 변경하지 않도록 함. 2. 라이브러리 적용 library(dplyr) # 라이브러리 적용 detach("package:dplyr", unload =TRUE) # 라이브러리 해제 3. dplyr (sql함수를 적용할 수 있다, pipe함수를 사용할 수 있다.) %>% : shortcut(ctrl+shift+m) # pipe함수를 통해 매개변수를 전달해 줄 수 있다. reserve_tb reserve_tb %>% select(reserve_id, hotel_id, customer_id, reserve_da.. 2020. 2. 13.
반응형