import numpy as npdata = np.random.randn(2,3) 랜덤값을 채운 행렬반환data * 10 각항목에 연산 가능data * data 행렬 항목간 연산data.dtype, data.shape 항목의 데이터 타입, 행렬 사이즈 보기 np.zeros(size) 사이즈를 튜플로 받아 0 행렬을 준다np.arange(start, end, step) 배열 리턴np.dot(arr1, arr2) 행렬 곱 ndarray.reshape(튜플) 배열 재구성ndarray.T Transpose (배열 전치), 데이터 복사 없이 뷰를 반환함 Universial function ( 고속연산 )np.sqrt(arr) square rootnp.exp(arr) exponential 밑이 자연상수 e인 지수함..
python re module로 제공 - search - match - findall - sub - split - compile re.search(query, content) 리턴 _sre.SRE_Matchre.match(query, content) 리턴 _sre.SRE_Match m = re.search(r'^b\w+', 'banana')print m.group() 리턴 str findall(query, content) 리턴 listsub(query, replace, content) 리턴 str sub 응용replace 는 text 가 올 수도 있고 패턴이 올 수도 있다pattern = r'(\d{3})-(\d{4})-(\d{4})'replace = r'(\1) \2-\3' result = re.sub..
TF : term frequency 총 문서에서의 단어 출현빈도 DF : document Frequency 문서빈도 = 출현문서 수/총문서 수 IDF : inverse document frequency DF역수의 로그값 = log(총문서 수 / 출현문서 수) class 연습문제 tf-idf 구해보세요.data_set/tf_idfx.txt를 읽어들여 각 단어들의 tf-idf 를 구하시오term frequency : 각 문서에서 해당 단어가 나오는 빈도document frequency : 해당 단어가 얼마나 많은 문서에서 나타나는가 하는 빈도inverse document frequency : 1/dftips import os os.walk 사용하기
df['datetime'] = df['date'].apply(lambda x: pd.to_datetime(str(x), format='%Y%m%d’)) - .apply(lambda x: ~는 내가 x를 다룰건데, 어떻게 할거냐면~ 이라는 뜻입니다. 여기서는 %Y%m%d 형식으로 된 x를 pandas의 to_datetime 함수를 통해 datetime object로 변환하는 겁니다. 만약 원본값이 2015-01-01이라면 format을 %Y-%m-%d로 바꿔주면 됩니다.
import matplotlib as mplimport matplotlib.pylab as pltimport numpy as np xlist = [10,20,30,40]ylist = [1,4,9,16] plt.plot(xlist, ylist ,'rs:')plt.plot(ylist, c="b", lw=5, ls="--", marker="o", ms="15", mec="g", mew=5,)plt.hold(True)plt.plot([9,16, 4, 1], c="k", lw=3, ls=":", marker="s", ms=10, mec="m", mew=5, mfc="c")plt.hold(False)plt.xlim(-0.2, 3.2)plt.ylim(-1,18)plt.show() --------------------..
요약 : a*2를 한 번 할 시간이면 a a b a를 b만큼 왼쪽으로 민다는 것은 a를 2의 b승만큼 곱하는 것과 같다. 이 공식은 b가 음수일 때도 똑같이 적용된다. a를 -1만큼 왼쪽으로(즉 오른쪽으로 한칸) 밀면 2-1를 곱하는(즉 2로 나누는)것과 같다. 그래서 곱셈 대신에 쉬프트 연산을 사용할 수 있는데 이 두 연산은 엄청난 속도 차이가 있다. 비트를 이동시키는 것과 일정 횟수 더하기를 반복하는 것은 CPU 입장에서 보면 완전히 다른 작업이기 때문에 속도차가 무려 10배 정도 난다. 쉬프트 연산은 전혀 논리적이지 않으며 기계적이므로 기계가 하기에는 아주 쉬운 연산인 것이다.즉 a*2를 한 번 할 시간이면 a . 이렇게 속도차가 나기 때문에 핵심 게임 엔진이나 시스템 프로그래머들은 곱셈 대신..
Series Parameters:data : array-like, dict, or scalar valueContains data stored in Seriesindex : array-like or Index (1d)Values must be unique and hashable, same length as data. Index object (or other iterable of same length as data) Will default to RangeIndex(len(data)) if not provided. If both a dict and index sequence are used, the index will override the keys found in the dict.dtype : numpy.d..
fout = open('school', 'w') # 쓰기 모드로 파일을 오픈 (존재한다면, 덮어씀)#fout = open('school', 'a') # 쓰기 모드로 파일을 오픈 (존재한다면, 맨 뒤에서 부터 추가)fout.write(speech)fout.close() with open('school', 'r') as fin: value = fin.read() print value csv 쓰기import csv with open('sample.csv', 'r') as f: reader = csv.reader(f) reader.next() with open('result2.csv', 'w') as fw: writer = csv.writer(fw) writer.writerow(['city', 'populati..