분류 전체보기 (102) 썸네일형 리스트형 [Hive] 04. 날짜 다루기 (string -> date) string 형태로 된 날짜값을 날짜type으로 변경하기!! select from_unixtime(unix_timestamp(string_col, 'yyyymmdd'), 'yyyy-mm-dd') # 2020-01-01 ,from_unixtime(unix_timestamp(string_col, 'yyyymmdd'), 'yyyymmdd') # 20200101 from table ; 07_01_42. replace를 이용한 컬럼명 변경 (replace string in list) # 컬럼명 replace로 변경 ( item -> delv로 변경) df_delv_01.columns = [x.replace('item','delv') for x in df_delv_01.columns] 07_01_41. 그래프 범례 삽입 (graph legend), 여러 line 겹쳐 그리기 여러개 plot이 존재할 때, 범례 추가하기 from matplotlib import pyplot as plt import matplotlib.pylab as plt2 plt2.rcParams["figure.figsize"] = (15,4) # plot 크기 조절 fig, ax0 = plt.subplots() ax0.set_xlabel('date') ax0.set_ylabel('amt') # 메인 축 label (축이름) ax0.set_ylim(1000000,2400000) # 메인 축 범위 조절 line0 = ax0.plot( df_tot['datecd'], df_tot['amt'], color='black' , label='tot') # 2중축 추가 ax1 = ax0.twinx() ax1.set_yl.. 07_01_40. matplotlib plot 크기 조정 (plot size) %matplotlib inline import matplotlib.pylab as plt plt.rcParams["figure.figsize"] = (14,4) plt.rcParams['lines.linewidth'] = 2 plt.rcParams['lines.color'] = 'r' plt.rcParams['axes.grid'] = True 항목설명 "figure.figsize" 그림(figure)의 크기. (가로,세로) 인치 단위 'lines.linewidth' 선의 두께 'lines.color' 선의 색깔 'axes.grid' 차트내 격자선(grid) 표시 여부 07_01_39. matplotlib 그래프 이중축 graph 생성 및 축이름 import pandas as pd from matplotlib import pyplot as plt fig, ax0 = plt.subplots() ax1 = ax0.twinx() ax0.plot( df_tot['part_datecd'], df_tot['ntsal_amt_m'], color='black') ax1.plot( df_tot['part_datecd'], df_tot['ntsal_amt_ff_m'] , color='blue') ax0.set_xlabel('date') ax0.set_ylabel('amt') ax1.set_ylabel('amt(1') 07_01_38. pivot_table index를 column으로 (index to column) df_ff_01 = pd.pivot_table( df_ff , index =['part_datecd'] , columns='good_cls1cd', values=['ntsal_amt','sal_qty']) df_ff_01.columns = list(map('_'.join, df_ff_01.columns)) # index에 지정된 column이 index화 되기 때문에 그걸 다시 column으로 변경시킴 df_ff_01.reset_index(level=0, inplace=True) 02_01_01. 의사결정나무 Decision Tree 작년에 다시 더듬어 공부하면서 정리한 내용을 포스팅해보려고 한다~ :) 변수의 규칙 또는 조건문을 토대로 나무 구조로 도표화하여 분류와 예측을 수행하는 방법 : 대상이 되는 집단을 몇 개의 소집단으로 구분하는 Segmentation 모델링 기법 (그룹의 특성을 발견하고자 하는 경우) : Feature Selection에 사용되기도 함 (변수선택) 1) 장점 - 이해와 해석이 쉬움 - 비모수적 모형, 결측값을 효과적으로 다룰 수 있음 - 계산이 빠름 - 교호작용을 고려할 수 있음 - Transformation해도 변화가 없음 - 분포에 대한 가정이 필요 없음 - 비선형적 2) 단점 - 교호작용 지나치게 강조 - 예측 표면이 부드럽지 않음 - 같은 데이터로 다른 Tree들을 만들 수 있음 - 불안정함 (분산.. [Impala] 03. 테이블 Create 생성 + partition 추가 create table Schema.tablename ( col1 string, col2 decimal(38,2) ) partitioned by (partition_col col_type) stored as parquet; insert into Schema.tablename partition(partition_col) select col1 ,col2 ,partition_col from table ; [Hive] 02.현재 날짜 다루기 select from_unixtime(unix_timestamp()) ,from_unixtime(unix_timestamp(), 'yyyymmdd') ,from_unixtime(unix_timestamp(), 'yyyy-mm-dd') ,cast(from_unixtime(unix_timestamp(), 'yyyy-mm-dd') as date); [결과] 09_06. 나이스교육정보개방포털 API - 학사일정 전국 학교의 학사일정 데이터를 가져와보고자 함 1. 모듈 불러오기 import requests import re import pandas as pd import json import os import time, datetime from dfply import * from urllib.request import urlopen import math 2. today 날짜 Setting today = datetime.date.today().strftime('%Y%m%d') 3. API 인증키 api_key = 'api 인증키 입력' 4. 이전 09_05(1) 에서 수집한 학교 list 정보 가져오기 (첨부) → 학교코드 사용 (sd_schul_code) https://based-infos.tistory.com/.. 이전 1 2 3 4 5 6 7 8 ··· 11 다음