跳至主要内容

博文

目前显示的是标签为“Python”的博文

Python - inline nested for

year = ['2017', '2018'] date = [y + str(month).zfill(2) for y in year for month in range(1, 12)] print(date) >>> output ['201701', '201702', '201703', '201704', '201705', '201706', '201707', '201708', '201709', '201710', '201711', '201801', '201802', '201803', '201804', '201805', '201806', '201807', '201808', '201809', '201810', '201811'] Zfill() Methond str.zfill(length) 문자열의 길이가 인자값인 length가 될때까지 왼쪽으로부터 0으로 삽입하여 반환 s = '100' print(s.zfill(5)) s = '+82' print(s.zfill(5)) >>> output 00100 +0082

Pandas

pandas. to_numeric  pandas .to_numeric(arg, errors = 'raise', downcast = None) numeric type으로 변환 Parameters: arg  :  list, tuple, 1 차원 배열 , or Series errors  : {‘ignore’, ‘raise’, ‘coerce’}, default 는 ‘raise’       ·          ‘raise’: invalid parsing 시 exception 발생 ('pandas' 문자열은 파싱 불가 )       ·          ‘coerce’: invalid 한 값은 NaN 값으로 캐스팅       ·          ‘ignore’: 원 데이터 값대로 데이터 반환 downcast  : {‘integer’, ‘signed’, ‘unsigned’, ‘float’} , default None Returns: numeric으로 캐스팅한 값을 반환, 입력된  arg인자 값이 Series면 Series을 반환하고 그 외에는 ndarray을 반환 pandas .DataFrame.astype DataFrame .astype (dtype, copy = True, errors = 'raise', **kwargs) object를 특정 타입으로 캐스팅 Parameters: dtype  : 캐스팅하려는    data ...

Pandas Plot

pandas.DataFrame.plot.bar import matplotlib.pyplot as plt import pandas as pd import numpy as np df = pd.DataFrame(np.random.rand(5, 4).round(1),                   index=['snail', 'pig', 'elephant','rabbit', 'giraffe'],                   columns=pd.Index(['speed', 'lifespan', 'active', 'cuite'],                   name='Genus')) ax = df.plot(kind='bar',figsize=(10,4), rot = 0) plt.show() ==> output in Pycharm

Python - Numpy

random module np.random. normal (loc = 0.0, scale = 1.0, size = None) 정규 분포 확률 밀도에서 표본 추출함. 생성된 난수는 정규 분포의 형상을 가짐 Parameters: loc :  정규분포 평균 ( 중심점 ) scale :  표준편차 size : Output shape.  개수 혹은  ( 행 ,  열 ) Returns: out :  설정된  parameters 에 따른   ndarray or scalar  값을 반환 ex) np.random.normal(0, 1, (2, 3)) 평균이 0 이고 표준편차가 1 인 정규분포를 띄는 2x3 의 행렬 값을 반환 받음

자료형_문자열형

CHAR형 (고정 길이 문자열)  최대 길이를 지정하여 문자열을 저장     CHAR(10) : 최대 10문자로 된 문자열을 저장 VARCHAR형 (가변 길이 문자열) 최대 길이를 지정하나, 데이터 크기에 맞춰 저장공간이 변경, 즉 저장되는 문자열의 길이에 맞는 가변적인크기를 가짐 문자열형 상수를 검색 조건으로 지정 SELECT 열 FROM 테이블명 WHERE 조건식 조건식에 문자열형을 비교할 경우 싱글쿼트('')로 둘러싸야 함 예) SELECT * FROM table WHERE name = 'XXX' 자료형에 맞게 표기한 상수값을 literal이라고 하는데 문자열 literal은 싱글쿼트로 표기 문자열 상수 '의 이스케이프 문자열 상수 안에 '를 포함해야 하는 경우 '를 2개 연속 기술 (' -> '') It's -> 'It''s'