아래 네줄은 거의 고정 import requestsfrom bs4 import BeautifulSoup res = requests.get('http://www.naver.com')soup = BeautifulSoup(res.content) res.content 는 stringres.text 는 유니코드 Beautiful Soup Object (객체)Tag, NavigableString, BeautifulSoup, Comment .Name.attrs / [' ']Tag의 속성은 Dictionary처럼 추가,삭제,수정 할수 있다 find return bs4.element.Tagfind_all return bs4.element.ResultSet body = soup.find ( 'div', attrs ={'c..
#-*-coding: utf-8 -*-를 코드 처음에 다 붙인다 a = '한글'print a 윈도우의 경우 유니코드로 갔다가 다시 cp949로 가야 텍스트로 사용가능하다print a.decode('utf-8').encode('cp949') python3 는 unicode만으로 사용하므로 이 문제가 없다 ----------------------------------------------------------------------------unicode(a) # 기본적으로 ascii를 읽어드리려 한다, 당연히 에러 import sysreload(sys)sys.setdefaultencoding('utf-8') 를 붙여주면 이후 코드에 a.decode('utf-8') 과 같은 효과가 있다 명령어 chcp 코드명..
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인 지수함..
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() --------------------..
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..
import sys from PyQt4.QtGui import * from PyQt4.QtCore import * import matplotlib.pyplot as plt from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas import pandas_datareader.data as web class MyWindow(QWidget): def __init__(self): super().__init__() self.setupUI() def setupUI(self): self.setGeometry(600,200, 1200, 600) self.setWindowTitle("PyChart Viewr v0.1") self.se..
DataFrame.to_sql(name, con, flavor='sqlite', schema=None, if_exists='fail', index=True, index_label=None, chunksize=None, dtype=None) import sqlite3 con = sqlite3.connect("C:\SQLite3\kospi.db") cursor = con.cursor() cursor.execute("CREATE TABLE kakao(Date text, Open int, High int, Low int, Closing int, Volume int)")cursor.execute("INSERT INTO kakao VALUES('16.06.03', 97000,98600,96900,98000,3214..