참고글 : [Python] 피벗 (.pivot, .pivot_table) [Python 시각화] 막대 그래프 그리기 (matplotlib API) import pandas as pd import numpy as np from pandas import Series, DataFrame from numpy import nan as NA matplotlib API cmd 모드로 사용 시, - pylab 모드로 실행 : ipython --pylab - pylab 모드로 전환 : %matplotlib qt import matplotlib.pyplot as plt #. 선 그래프(Line Plot) 그리기 - figure : 그래프를 그릴 수 있는 도화지 (subplot만으로도 그래프 생성이 가능하지만, 특정 그래프..
정규표현식 (re Module) #. re 모듈import re - 정규식 처리 모듈- 패턴 매칭, 치환, 분리 text = 'lololo' 1. findall 메서드 - re.findall(pattern, string, flags=0) - 패턴과 일치하는 모든 원소 출력 * 주로 사용 - 벡터 연산 불가re.findall('ol', text)['ol', 'ol'] 2. search 메서드 - re.search(pattern, string, flags=0) - 패턴과 일치하는 첫 번째 원소 출력 - 직접 출력 불가 => group 메서드 사용re.search('ol', text)re.search('ol' , text).group(0)'ol' 3. match 메서드- re.match(pattern, str..
참고글 : [Python] Pandas - DataFrame[Python] Pandas - DataFrame 관련 메서드 #. 문자열 분리, 결합, 공백 제거 (.split, .join, .strip)# 문자열 분리 : split메서드pro.EMAIL0 captain@abc.net1 sweety@abc.net...14 napeople@jass.com15 silver-her@daum.netName: EMAIL, dtype: object pro.EMAIL.map(lambda x : x.split('@')) # 벡터 연산 불가0 [captain, abc.net] 1 [sweety, abc.net]...14 [napeople, jass.com]15 [silver-her, daum.net]Name: EMAIL, ..
import pandas as pd import numpy as np from pandas import Series, DataFrame #. 배열 결합 (np.concatenate)np.concatenate?concatenate((a1, a2, ...), axis=0, out=None) ar1 = np.arange(4).reshape(2,2)array([[0, 1], [2, 3]])np.concatenate([ar1, ar1], axis=1)array([[0, 1, 0, 1], [2, 3, 2, 3]])np.concatenate([ar1, ar1], axis=0)array([[0, 1], [2, 3], [0, 1], [2, 3]]) #. 데이터 프레임 결합 (pd.concat)pd.concat?pd.co..
# xlrd, openpyxl 패키지 설치> conda install xlrd > conda install openpyxl # excel 파일 불러오기 (pd.ExcelFile, .parse)xls_file.parse?xls_file.parse(sheet_name=0, header=0, names=None, index_col=None, usecols=None, squeeze=False, converters=None, true_values=None, false_values=None, skiprows=None, nrows=None, na_values=None, parse_dates=False, date_parser=None, thousands=None, comment=None, skipfooter=0, co..
import pandas as pdimport numpy as npfrom pandas import Series, DataFrame # 데이터 병합(Join) - pandas.mergedf1.merge?df1.merge(right, how='inner', on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=False, suffixes=('_x', '_y'), copy=True, indicator=False, validate=None) # 주요 옵션# how : join 방법 (default는 inner join), - Outer Join은 'outer' / Inner Join은 'inner' / Left Join은..
Multi-index & Multi-column #. 생성 - 인덱스의 개수, 상위 level & 하위 level의 개수가 일치해야 함 - 생성할 일은 많지 않음 :( 1. Series s1 = Series([1,2,3,4,5,6], index=[['a','a','b','b','c','c'], [1,2,1,2,1,2]]) s1a 1 1 2 2 b 1 3 2 4 c 1 5 2 6 dtype: int64 2. DataFrame 생성 후 설정 df1 = DataFrame({'value':[1,2,3,4,5,6], 'ind1':['a','a','b','b','c','c'], 'ind2':[1,2,1,2,1,2]}) df1 = df1.set_index(['ind1','ind2']) # 리스트 형식으로 인덱스에 동..
참고글[Python] Pandas - Series [Python] Pandas - DataFrame[Python] DataFrame 그룹 함수 적용(map,apply,applymap) # 행/열 전치 (T 메서드)fruits.T 0 1 2 3nameapplemango bananacherryprice2000 150 500 400qty 5 4 10 NaN # 연산 (add, sub, div, mul 메서드)# NA 처리 가능한 연산 메서드 df1 = DataFrame({'a':[1,2,3], 'b':[10,NA,20]})a b0 1 10.01 2 NaN2 3 20.0 df2 = DataFrame({'b':[1,2,3], 'c':[10,NA,20]}, index = [0,1,3])b c0 1 10.01 2 N..