배열 분리(dsplit) numpy.dsplit(ary, indices_or_sections) Python split 함수 참조 배열다루기 | 배열 분리(Numpy.split) 배열 분리(Split) numpy.split(ary, indices_or_sections, axis=0) 배열을 여러개의 하위 배열로 분리합니다. ▪Parameters ‣ ary : 입력 배열, ‣ indices_or_sections : 'Integer'인 경우, 축을 따라 동일한 N개의 배열로 분 moonnote.tistory.com TIP 차이점은 dsplit은 axis=2에 대해 동등하게 배열을 분리(3D 배열 이상 사용 가능) ▪Parameters ‣ ary : 입력 배열, ‣ indices_or_sections : 정수 ..
배열 분리(vsplit) numpy.vsplit(ary, indices_or_sections) Python split 함수 참조 배열다루기 | 배열 분리(Numpy.split) 배열 분리(Split) numpy.split(ary, indices_or_sections, axis=0) 배열을 여러개의 하위 배열로 분리합니다. ▪Parameters ‣ ary : 입력 배열, ‣ indices_or_sections : 'Integer'인 경우, 축을 따라 동일한 N개의 배열로 분 moonnote.tistory.com TIP 차이점은 vsplit은 axis=0에 대해 동등하게 배열을 분리(2D 배열 이상 사용 가능) ▪Parameters ‣ ary : 입력 배열, ‣ indices_or_sections : 정수 ..
배열 분리(hsplit) numpy.hsplit(ary, indices_or_sections) Python split 함수 참조 배열다루기 | 배열 분리(Numpy.split) 배열 분리(Split) numpy.split(ary, indices_or_sections, axis=0) 배열을 여러개의 하위 배열로 분리합니다. ▪Parameters ‣ ary : 입력 배열, ‣ indices_or_sections : 'Integer'인 경우, 축을 따라 동일한 N개의 배열로 분 moonnote.tistory.com TIP 차이점은 hsplit은 axis=1에 대해 동등하게 배열을 분리, 다만, 1D Array의 경우 axis=0을 기준으로 Split 수행 !! ▪Parameters ‣ ary : 입력 배열, ..
배열 분리(Array_split) numpy.array_split(ary, indices_or_sections, axis=0) Python split 함수 참조 배열다루기 | 배열 분리(Numpy.split) 배열 분리(Split) numpy.split(ary, indices_or_sections, axis=0) 배열을 여러개의 하위 배열로 분리합니다. ▪Parameters ‣ ary : 입력 배열, ‣ indices_or_sections : 'Integer'인 경우, 축을 따라 동일한 N개의 배열로 분 moonnote.tistory.com TIP 차이점은 indices_or_sections이 정수 입력만 가능하며 축을 균등하게 분리하지 않음 !! ▪Parameters ‣ ary : 입력 배열, ‣ in..
배열 분리(Split) numpy.split(ary, indices_or_sections, axis=0) 배열을 여러개의 하위 배열로 분리합니다. ▪Parameters ‣ ary : 입력 배열, ‣ indices_or_sections : 'Integer'인 경우, 축을 따라 동일한 N개의 배열로 분리 '1D Array'인 경우, 축을 따라 지정된 구간을 기준으로 입력 배열을 분리 * 예시: [2, 3]으로 입력할 경우, ary[:2], ary[2:3], ary[3:] 로 분리 ‣ axis : 축 설정(optional) ‣ Returns : sub-arrays(list of ndarrays), 분리된 배열 반환 예제(Example) import numpy as np x = np.arange(9.0) out..
부모 태그 찾기(Find Parent Function) find_parent(), find_parents() BeautifulSoup에서 지정된 조건에 해당하는 부모 태그를 찾아주는 함수 예제(Example) ▪ html_doc 문서(더미 데이터)를 생성하고 find_parent 함수로 Lacie의 a 태그를 검색 from bs4 import BeautifulSoup html_doc = """ The Dormouse's story Once upon a time there were three little sisters; and their names were Elsie, Lacie and Tillie; and they lived at the bottom of a well. ... """ soup=Beauti..
내용 찾기(Find Function) find(), find_all() BeautifulSoup에서 지정된 조건에 해당하는 내용을 찾아주는 함수 예제(Example) ▪ html_doc 문서(더미 데이터)를 생성하고 find 함수로 a 태그를 검색 (find 함수의 경우 1개만 검색) from bs4 import BeautifulSoup html_doc = """ The Dormouse's story Once upon a time there were three little sisters; and their names were Elsie, Lacie and Tillie; and they lived at the bottom of a well. ... """ soup=BeautifulSoup(html_doc,..
계층 구조 파싱 함수(Parse Tree Function) prettify() BeautifulSoup에서 파싱 처리한 파서 트리를 유니 코드 형태로 변환해주는 함수 예제(Example) ▪ html_doc 문서(더미 데이터)를 생성하고 이를 prettify로 출력 from bs4 import BeautifulSoup html_doc = """ The Dormouse's story Once upon a time there were three little sisters; and their names were Elsie, Lacie and Tillie; and they lived at the bottom of a well. ... """ soup = BeautifulSoup(html_doc, 'html.pa..
엑셀 파일(실행 후 결과 값) 엑셀 파일 구성 코드 실행 후 파일 저장 ▪ [Exam 01]Remove_duplicates_by_row.xlsx ▪ [Exam 02]Remove_duplicates_by_column.xlsx 중복 제거 예제 코드 01 (행 기준) ▪ DataFrame을 사용하여 중복 데이터가 있는 테이블을 생성 ▪ dataframe_to_rows 함수를 사용하여 DataFrame의 데이터를 시트에 작성 ▪ iter_rows 메서드를 사용하여 시트의 모든 행을 가져오고, seen 집합을 사용하여 중복 데이터를 확인 ▪ 중복이 없는 행은 rows_without_duplicates 리스트에 추가 후 중복 제거된 데이터만 시트에 작성 from openpyxl import Workbook from..
배열 차원 변경(Reshape Function) numpy.reshape(a, newshape, order='C') 배열의 차원을 변경합니다. ▪Parameters ‣ a : 입력 배열, ‣ newshape : 변경할 차원 지정, *설명 ‣ order : 'C', 'F', 'A' 중 선택 사항, 'C' (C-like order): C 스타일의 인덱스 순서를 의미(예: 2차원 배열에서 행(row) 우선으로 요소에 접근) 'F' (Fortran-like order): Fortran 스타일의 인덱스 순서를 의미(예: 2차원 배열에서 열(col) 우선으로 요소에 접근) 'A' (Any order): 메모리에서 Fortran 형식으로 연속적으로 저장되어 있다면 Fortran 스타일의 인덱스 순서를, 아닐 경우 C..
배열 차원 및 크기 반환(Shape Function) numpy.shape(a)[source] 배열의 차원과 크기를 반환합니다. ▪Parameters ‣ a : 입력 배열, ‣ Returns : Shape, 배열 크기 반환 예제(Example) import numpy as np a = np.array([1, 2, 3, 4, 5]) shape = np.shape(a) print(shape) # Output: (5,) Result (5) import numpy as np a = np.array([[1, 2, 3], [4, 5, 6]]) shape = np.shape(a) print(shape) # Output: (2, 3) Result (2,3) import numpy as np a = np.array([[..
문자열(String) 위키백과를 참조하면 기호의 순차 수열이라고 설명하고 있는데 쉽게 설명하면 말 그대로 문자들의 열을 말합니다. 예를 들어 'H'는 문자지만, 'Hello'는 문자열이라고 할 수 있는 것이죠. 스트링(String)이라고 많이들 부르며 str로 줄여서 표기하기도 합니다. 문자마다 PC가 이해할 수 있도록 고유의 이진 값(0 or 1)이 있는데 이해를 돕기 위해 대표적인 ASCII 코드표를 첨부하였으니 참고하시면 좋을 듯 합니다. 문자열 표현 파이썬에서 문자열 데이터를 표현하는 방법은 큰 따옴표("") 또는 작은 따옴표('')를 사용하여 표현할 수 있습니다. String1 = "MoonNote" String2 = 'Python String Type' print(String1) print(S..
엑셀 파일(실행 후 결과 값) 엑셀 파일 구성 코드 실행 후 파일 저장 ▪ A1 : Hello, B1 : World, C1 : Created by MoonNote 좌표 출력(Coordinate) 예제 코드 cell.coordinate : 현재 작업 중인 좌표의 위치를 출력할 때 사용 from openpyxl import Workbook # Create a new workbook workbook = Workbook() # Select the activated workbook sheet = workbook.active # Write the A1 value to 'Hello' sheet['A1'] = 'Hello' # The coordinate output of the A1 cell cell = sheet['..
조건적 출력(Extract Function) numpy.extract(condition, arr) 입력 배열에서 지정한 조건을 만족하는 원소만 출력합니다. ▪Parameters ‣ condition : 조건적 불리언 배열, 조건 입력(TRUE/FALSE)으로 이루어진 1D Array ‣ arr : 입력 배열, ‣ Returns : ndarray, 조건을 만족하는 배열만 출력 예제(Example) import numpy as np a = [1,2,3,4,5] condition = [True, False, True, False, True] print('Result : ', np.extract(condition, a)) Result Result : [1 3 5] import numpy as np a = [[1..
조건적 출력(Compress Function) numpy.compress(condition, a, axis=None, out=None) 입력 배열에서 지정한 조건을 만족하는 원소만 출력합니다. ▪Parameters ‣ condition : 조건적 불리언 배열, 조건 입력(TRUE/FALSE)으로 이루어진 1D Array ‣ a : 입력 배열, ‣ axis : 축 설정(선택 사항), 계산이 진행되는 축 설정 ‣ out : 출력 배열(선택 사항), ‣ Returns : ndarray, 조건을 만족하는 배열만 출력 예제(Example) import numpy as np a = [1,2,3,4,5] condition = [True, False, True, False, True] print('Result : ',..
양쪽 0값 제거(Trim_zeros Function) numpy.trim_zeros(filt, trim='fb') 배열 양 쪽 끝에 0값을 제거해줍니다. ▪Parameters ‣ flit : 입력 배열, ‣ trim : 트림 조건, 앞에서 트림은 'f', 뒤에서 트림은 'b', 기본값은 'fb' ‣ trimmed : 출력 배열, 트림된 1D 배열 출력 예제(Example) import numpy as np a = [0, 0, 0, 1, 2, 3, 4, 0, 0, 0] print(np.trim_zeros(a, 'f')) Result [1, 2, 3, 4, 0, 0, 0] import numpy as np a = [0, 0, 0, 1, 2, 3, 4, 0, 0, 0] print(np.trim_zeros(a,..
배열 중복 요소 제거 함수(Unique Function) numpy.unique(ar, return_index=False, return_inverse=False, return_counts=False, axis=None, *, equal_nan=True) 배열의 중복된 원소를 제거해 줍니다. ▪Parameters ‣ ar : 입력 배열, ‣ return_index : 인덱스 반환(선택 사항), 중복 제거 배열(고유 배열)에 대한 index 정보 반환 ‣ return_inverse : 인덱스 반환(선택 사항), 입력 배열에 대한 index 정보 반환 ‣ return_counts : 중복 횟수 반환(선택 사항), 입력 배열에 대한 중복 횟수 정보 반환 ‣ axis : 축 설정(선택 사항), 계산이 진행되는 축..
배열 요소 삭제 함수(Delete Function) numpy.delete(arr, obj, axis=None) 지정한 Index의 요소를 삭제시켜주는 함수입니다. ▪Parameters ‣ arr : 입력 배열, ‣ obj : 값 추가 전 인덱스를 지정하는 개체 삽입(slice or Index), ‣ axis : 축 설정(선택 사항), 계산이 진행되는 축 설정 ‣ out : ndarray, 삭제된 배열 출력 값(axis 지정이 없다면 1D Array 형태로 출력) 예제(Example) import numpy as np a = np.arange(1, 10, 1) print('Initial np values : ', a) a = np.delete(a, 0) print('1st delete data : ', ..
배열 요소 삽입 함수(Insert Function) numpy.insert(arr, obj, values, axis=None) 지정한 index에 요소를 끼워 넣어주는 함수입니다. ▪Parameters ‣ arr : 입력 배열, ‣ obj : 값 추가 전 인덱스를 지정하는 개체 삽입, ‣ values : 추가할 값, ‣ axis : 축 설정(선택 사항), 계산이 진행되는 축 설정 ‣ out : ndarray, 추가된 배열 출력 값 (axis 지정이 없다면 1D Array 형태로 출력) 예제(Example) import numpy as np np = [] np.insert(0, 1) print('1st insert data : ', np) np.insert(0, 2) print('2nd insert dat..
배열 요소 추가 함수(Append Function) numpy.append(arr, values, axis=None) 입력 배열 마지막에 요소를 추가해주는 함수입니다. ▪Parameters ‣ arr : 입력 배열, ‣ values : 추가할 값, ‣ axis : 축 설정(선택 사항), 계산이 진행되는 축 설정 ‣ append : ndarray, 추가된 배열 출력 값 (axis 지정이 없다면 1D Array 형태로 출력) 예제(Example) import numpy as np np = [] np.append(1) np.append(2) np.append(3) np.append(4) np.append(5) print(np) Result [1, 2, 3, 4, 5] import numpy as np np =..
엑셀 파일 엑셀 파일 구성 예제 실행시 사용하였던 엑셀 파일 데이터 및 시트 정보 ▪ 1행 5열 데이터셋 Cell 값 쓰기(2가지 방법 : ¹['Cell'].value, ²cell(row=x, column=y).value) import openpyxl from openpyxl import load_workbook # You must change the physical path before running this script. currPath = "C:/Users/natio/OneDrive - 성균관대학교/99. Personal Blog/05. Python/05. OPENPYXL/02. Cell Example/" # # Load the excel file wb = openpyxl.load_workbook(..
엑셀 파일 엑셀 파일 구성 예제 실행시 사용하였던 엑셀 파일 데이터 및 시트 정보 ▪ 5행 5열 데이터셋 max_row, max_column 명령어를 이용한 행•열 사이즈 검색 import openpyxl from openpyxl import load_workbook # You must change the physical path before running this script. currPath = "C:/Users/natio/OneDrive - 성균관대학교/99. Personal Blog/05. Python/05. OPENPYXL/02. Cell Example/" # # Load the excel file wb = openpyxl.load_workbook(filename=currPath+"Cell Ex..
엑셀 파일 엑셀 파일 구성 예제 실행시 사용하였던 엑셀 파일 데이터 및 시트 정보 ▪ 5행 5열 데이터셋 Cell 값 읽기(2가지 방법 : ¹['Cell'].value, ²cell(row=x, column=y).value) import openpyxl from openpyxl import load_workbook # You must change the physical path before running this script. currPath = "C:/Users/natio/OneDrive - 성균관대학교/99. Personal Blog/05. Python/05. OPENPYXL/02. Cell Example/" # # Load the excel file wb = openpyxl.load_workbook(..
백분위수(qercentile) numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, method='linear', keepdims=False, *, interpolation=None) 지정된 축을 따라 데이터의 q번째 백분위수를 계산합니다. ▪Parameters ‣ a : 입력 배열, 평균 값을 연산할 입력 배열 ‣ q : 입력 배열, 백분위수 입력(0~100 범위) ‣ axis : 축 설정(선택 사항), 계산이 진행되는 축 설정 ‣ out : 출력(선택 사항), 기본값 = None으로 결과를 저장할 대체 출력 배열 ‣ overwrite_input : 입력 덮어쓰기(선택 사항), 기본값 = False로 불리언 값으로 설정 ‣ method ..
최빈값(Unique Function) numpy.unique(ar, return_index=False, return_inverse=False, return_counts=False, axis=None, *, equal_nan=True) 입력 배열의 최빈값을 계산해줍니다. ▪Parameters ‣ ar : 입력 배열, 최빈값 계산을 위한 입력 배역 ‣ return_index : 인덱스 반환(선택 사항), 입력 배열 요소의 인덱스 정보를 반환하는 출력 배열을 생성 ‣ return_inverse : 고유 배열 index 반환(선택 사항), original 입력 배열을 재구성할 때 쓰이는 인덱스 정보를 반환하는 출력 배열을 생성 ‣ return_counts : 카운트 반환(선택 사항), 입력 배열 요소들의 카운터..
BeautifulSoup ◾ requests 모듈을 통해 요청을 보내고 결과 값을 받아오는 형태의 라이브러리 ◾ HTML , XML 파일로 데이터를 파싱해주는 라이브러리 ◾ 원하는 데이터를 특정 패턴이나 방법 또는 순서로 탐색, 검색, 수정 등 기능 수행 설치(Installation) pip 이용시, pip install beautifulsoup4 conda를 사용한다면, conda install beautifulsoup4 심플 예제(Example) ◾ HTML 예제 from bs4 import BeautifulSoup soup = BeautifulSoup("SomebadHTML", features="html.parser") print(soup.prettify()) ◾ 실행 결과 Some bad HTML..
엑셀 파일 엑셀 파일 구성 예제 실행시 사용하였던 엑셀 파일 데이터 및 시트 정보 ▪ 3행 4열 데이터셋 ▪ 3개 시트로 구성 엑셀 시트 색상 적용 import openpyxl from openpyxl import Workbook # You must change the physical path before running this script. currPath = "C:/Users/natio/OneDrive - 성균관대학교/99. Personal Blog/05. Python/05. OPENPYXL_XLRD_XLWT/01. Excel Sheet/" # Load the excel file wb = openpyxl.load_workbook(filename=currPath+"Sample Sheet File.xls..
최소값 함수(amin Function) numpy.amin(a, axis=None, out=None, keepdims=, initial=, where=) 배열 요소의 최소 값을 반환합니다. ▪Parameters ‣ a : 입력 배열, 평균 값을 연산할 입력 배열 ‣ axis : 축 설정(선택 사항), 계산이 진행되는 축 설정 ‣ out : 출력(선택 사항), 기본값 = None으로 결과를 저장할 대체 출력 배열 ‣ keepdims : 차원 유지(선택 사항), Bool 값으로 설정하고 True일 경우출력에서의 차원을 입력과 동일하게 유지 ‣ initial : 초기 값(선택 사항), where 'False' 설정된 곳을 initial 값으로 변경 ‣ where : 부울 배열을 승인(선택 사항), amax 계..
최대값 함수(amax Function) numpy.amax(a, axis=None, out=None, keepdims=, initial=, where=) 배열 요소의 최대 값을 반환합니다. ▪Parameters ‣ a : 입력 배열, 평균 값을 연산할 입력 배열 ‣ axis : 축 설정(선택 사항), 계산이 진행되는 축 설정 ‣ out : 출력(선택 사항), 기본값 = None으로 결과를 저장할 대체 출력 배열 ‣ keepdims : 차원 유지(선택 사항), Bool 값으로 설정하고 True일 경우출력에서의 차원을 입력과 동일하게 유지 ‣ initial : 초기 값(선택 사항), where 'False' 설정된 곳을 initial 값으로 변경 ‣ where : 부울 배열을 승인(선택 사항), amax 계..
주석(Comment) 주석은 쉽게 말해서 코드 실행이 되지 않는 부분이 말합니다. 보통 코딩을 할 때 특정 부분에 대한 설명을 기록하기 위해 주석 처리를 한다고 보면되는데 파이썬에서는 기본적으로 해시(#)를 사용해서 주석 처리를 합니다. # 주석 예시 # Moonnote Tistory Blog(Moonnote.tistory.com) # Python comment # print("사용 안하는 코드를 잠시 주석 처리합니다.") Print("코드 뒤에 주석으로 표시하기도 합니다.") # 주석 처리 VS Code에서 주석에 대한 단축키는 'Ctrl + /'로 쉽게 설정가능합니다. 2줄 이상 주석 표시하는 경우 위의 방법을 이용하여 ¹주석 표시할 부분을 전체 드래그하여 한번에 단축키(Ctrl+/)를 눌러서 처리하..