Upload
postech
View
54
Download
1
Embed Size (px)
Citation preview
2016-03-22(Tue)
Seunghoon Lee – PKM lab
Contents!
Python??
How to install Python??
Example code(keyword analysis)
기타 참고 사이트
Python??
프로그래밍 언어의 일종(C++, Java와 함께 Google의 3대 언어)
창시자는 Guido van Rossum.(현재 드롭박스 직원)
(1989년 크리스마스 주에, 연구실이 닫혀 있어서, 심심한 김에 만들었다고 전해짐)
“Over six years ago, in December 1989,
I was looking for a "hobby" programming project that would keep me occupied
during the week around Christmas.”
in Foreword for "Programming Python" (1st ed.)
Python의 장점 혹은 특징
1. 높은 생산성• 우수한 자료형과 다양한 모듈을 통해 개발기간을 단축 시킬 수 있다는 것이 강점.
• Scikit-learn, numpy, panda, Django 등 유용한 package가 다수 존재
• “C언어로 2년동안 완성하지 못한 프로젝트를 Python으로 한 달 만에 해냈다!”라는 경험담이 존재.
• 그러나, 인터프리터 언어이기 때문에, 속도는 느림. • Python으로 빨리 구현하고, 속도 상에서 문제가 되는 부분을 C로 전환하여 속도 향상
2. Pythonic• “There is only one way to do it”
• Perl: “There is more than one way to do it”과 정반대 되는 철학(ruby도 마찬가지)
• 프로그래머 간의 코딩 스타일이 발산하지 않고, Pythonic이라고 하는 특정한 스타일로 수렴하는 경향이 존재.
• 따라서 Python을 통해 구현된 코드는 가독성이 좋음. • 따라서 문법이 엄격함(특히 indentation)
Stackoverflow Developer Survey Results 2016
Most Popular Technologies: 5th rank21.9%(2013), 23.4%, 23.8%, 24.9%(2016)
Top Tech Stacks per occupation(Data Scientists)Necessary skills for Data Scientists
How to install Python
https://www.python.org/
Downloads =>
Python 3.5.1 or Python 2.7.11
Python 2.x와 3.x는 비슷하지만 다름. 예) 2.x: print “a”, 3.x: print(“a”)
처음 시작한다면 3.x를 추천.
기존에는 2.x만 지원하는 library가 많았으나 지금은 점차 증가하고 곧 2.x를 넘어갈 추세.
Example(Keyword analysis)
class keyword:
k_list=[]
year=0
doc_type=""
def __init__(self, input_year, input_doc_type, input_k_list):
self.year=input_year
self.doc_type=input_doc_type
self.k_list=input_k_list
Define Classdef return_similarity(keyword1, keyword2):
from difflib import SequenceMatcher
return SequenceMatcher(None, keyword1, keyword2).ratio()
Define Function
file_dir="!author_keyword_csv.csv"
f=open(file_dir)
temp=f.read()
f.close()File read
Keyword_line=temp.split(“\n”)
for i in range(0, len(keyword_line)-1):
keyword_tuple_list.append(keyword_line[i].split(","))
for j in range(0, len(keyword_tuple_list[i])):
keyword_tuple_list[i][j]=keyword_tuple_list[i][j].strip().lower()
for j in range(0, len(keyword_tuple_list[i])):
if keyword_tuple_list[i][-1]=="":
keyword_tuple_list[i].pop()
Keyword split
f=open(“aa.csv”, “w”)
f.write(“aaaa”)
f.close() File write
Install pip제어판 ==> 시스템 및 보안 ==> 시스템 ==> 고급 시스템 설정 ==>
고급 탭 ==> 환경 변수 ==> 시스템 변수에 Path 변수에 Python이 설치된 폴더 경로를 입력
(기존 내용을 삭제하지 않고 “;”으로 구분하여 입력)
완료하면, 윈도우+r ==> cmd에서 바로 python으로 실행 가능
추가로 pip 도 활용 가능
ex: pip install pandas ==> pandas module install
ex: pip install numpy ==> numpy module install
if it didn’t work
pip install –-upgrade pip
기타 참고 사이트들
Codecademy(https://www.codecademy.com/learn/python)
(File input/output, Class, function, data structure(dictionary/list)등)
Pythonlearn(http://pythonlearn.com/)
(Regular expression, database와의 연결, api 이용 까지 cover)
Intro to computer science(https://www.udacity.com/course/intro-to-computer-science--cs101)
(building own search engine using python)