본문 바로가기

Python_Intermediate

(155)
190428>Korea News keyword wordcloud 현재 뉴스에서 많이 사용중인 키워드 분석 시각화 모듈WordCloud를 활용하여 시각화190428 키워드 분석 시각화 imoprt module>from Crawler import crawler from bs4 import BeautifulSoup from wordcloud import WordCloud from matplotlib import pyplot from collections import Counter11940 from konlpy.tag import Okt import datetime as dt
Python Openpyxl - Sheet Delete(excel file) 1. excle 파일에 sheet를 삭제하는 방법 2. Openpyxl 모듈 임포트from openpyxl import Workbook 3. sheet del 기본 사용법wb.remove(wb['삭제할 시트 제목']) 4. 코드 정리sheet 안에 내용을 전체 삭제하는 명령어다. 5. 예제 코드from openpyxl import Workbook wb = Workbook() dest_filename = 'sample.xlsx' ws1 = wb.active ws1.title = 'sample excel' ws1['A1'] = 'Python excel' ws2 = wb.create_sheet() ws2.title = 'sample excel2' ws2['A2'] = 'Python excel' ws3 = wb..
Python Openpyxl - Sheet Add(excel file) 1. excel 파일에 sheet를 추가하는 방법 2. Openpyxl 모듈 임포트from openpyxl import Workbook 3. sheet add 기본 사용법from openpyxl import Workbook wb = Workbook() dest_filename = '파일명.xlsx' ws1 = wb.active ws1.title = '시트1 제목' ws1['셀번호'] = '문자열' ws2 = wb.create_sheet() ws2.title = '시트2 제목' ws2['셀번호'] = '문자열' ws3 = wb.create_sheet() ws3.title = '시트3 제목' ws3['셀번호'] = '문자열' wb.save(filename = dest_filename) 4. 코드 정리4-1...
Python Openpyxl - Cell Load(excel file) 1. Openpyxl의 여러 통합 문서 모드 로드 방법 중 셀 값 로드 방법 2. Openpyxl 모듈 임포트from openpyxl import load_workbook 3. Openpyxl 기본 사용법from openpyxl import load_workbook dest_filename = '파일명.xlsx' title = '시트명' wb = load_workbook(filename = dest_filename) sheet_ranges = wb[title] print(sheet_ranges['셀'].value) 4. 코드 정리4-1. 불러들일 엑셀 파일명 지정하여 변수에 저장dest_filename = '파일명.xlsx'4-2. 불러들일 시트명 지정하여 변수에 저장title = '시트명'4-3. 4-..
Python Openpyxl - write(excel file) 1. Python Openpyxl파이썬에 엑셀처리 패키지.특이점은 엑셀이 시스템에 설치가 되어있지 않아도 사용이 가능하다. 2. Openpyxl 설치pip install openpyxl 3. openpyxl 모듈 임포트import openpyxl 4. openpyxl 모듈 임포트 2from openpyxl import Workbook 5. openpyxl 기본 사용법from openpyxl import Workbook wb = Workbook() dest_filename = '파일명.xlsx' ws = wb.active ws.title = '시트명' ws['A1'] = 'A1 입력할 문자' wb.save(filename = dest_filename) 6. 코드 정리6-1. 작업할 워크북 생성wb = Wo..
Python Lotto Program Code1>import random lottonumber = random.sample(range(1, 46), 6) print(lottonumber) Code1 풀이>로또 번호는 가장 어찌보면 만들기 간단한 알고리즘이다.random 함수로 난수를 만들어서 무작위 추출법인 sampling 으로 처리하는 방식이다.이를 위해 Code 1은 random 함수안에 있는 sample 라는 함수를 불러들였다.또한 range 함수를 통해 로또의 범위인 1 ~ 45 / 그중 6개를 추출하는 형식으로 이루어진다. Code1 Output>[1, 21, 4, 24, 43, 18] Process finished with exit code 0 Code2>import random print('-' * 20) print('lotto..
Pandas Module CSV Read 1. Modulefrom pandas import read_csv 2. CSV File Load -> Pandas Data Framedataframe = read_csv('데이터경로', encoding='인코딩방식')인코딩방식 : ecu-kr / utf-8 3. Pandas Data Frame -> CSV File Savedataframe.to_csv('저정경로', encoding='인코딩방식', na_rep='결측치에할당문자', index=True|False, index_label='컬럼명', header=[csv의 컬럼명으로 사용할 리스트])na_rep : 기본값 빈 문자열 / index : True -> Index가 CSV File 저장, False -> Index가 CSV File 저장안됨Inde..
Chinese Character WordCloud Python Code>from wordcloud import WordCloud from matplotlib import pyplot from collections import Counter from PIL import Image import numpy text = '' with open("데이터위치", encoding="utf-8") as f: text = f.read(); tmp = list(text) hanja = [] ignore = [" ", "\n", ",", ".", "(", ")", "\U000f0703", "\ufeff"] for item in tmp: if item not in ignore: hanja.append(item.strip()) count = Counter(hanja) most..