본문 바로가기

Language

(15)
Pandas 심화 - 조건으로 검색하기 masking operation df = pd.DataFrame(np.random.rand(5,2), columns=["A","B"]) print(df["A"] < 0.5) print(df[(df["A"]0.3)]) print(df.query("A0.3")) 마스킹연산을 query를 사용해서도 할 수 있다. print(df["Animal"].str.contains("Cat")) print(df.Animal.str.match("Cat")) 문자열은 위와 같이 검색가능하다. - apply df = pd.DataFrame(np.arange(5), columns=["Num"]) # print(df["Num"].apply(lambda x: x**2)) df["Square"] = df.Num...
Pandas_Operations&function, Sort - Pandas 연산& 함수 - 누락된 데이터 체크 print(DF.isnull()) print(DF.notnull()) isnull()은 각 데이터가 비어있으면(nan, None) True, 아니면 False가 반환된다. - dropna(), fillna() print(DF.dropna()) DF['call'] = DF['call'].fillna('전화번호 없음') print(DF) .dropna()는 비어있는 data가 있으면 그 data row 전체를 날린다. .fillna()는 비어있는 곳에 채워준다. 이때, dataframe자체에 채워주는 곳이 아니라 반환해주는 메소드이므로 새로 선언해서 사용해야한다. - Series, DataFrame 연산 A = pd.Series([2,4,6], index=..
Pandas_Series, DataFrame Pandas란? 파이썬 라이브러리 구조화된 데이터를 효과적으로 처리하고 저장 Array 계산에 특화된 NumPy를 기반으로 설계 행과 열로 이루어진 데이터 객체를 만들어 다룰 수 있어, 데이터 처리와 분석하기 유용함 - Pandas 자료구조 Series: 1차원 DataFrame: 2차원 Panel: 3차원 - Series : numpy array가 보강된 형태 Data와 Index로 이루어져 있다. import pandas as pd data = pd.Series([1,2,3,4]) print(data) Index를 따로 선언해주지 않으면, 0부터 시작된다. 위 사진 기준, 좌측 Index, 우측 Data data = pd.Series([1,2,3,4],index=['a','b','c','d']) pr..
Numpy_Broadcasting, masking - Broadcasting : shape이 다른 array끼리 연산 ## 브로드캐스팅 matrix = np.array([[2,4,2],[6,5,9],[9,4,7]]) matrix2 = np.array([1,2,3]) print(matrix+matrix2) array1 = np.arange(3).reshape((3,1)) array2 = np.arange(3) print(array1+array2) 처음 예제 : 3x3 + 1x3 배열연산은 1x3행렬의 1행을 2,3행에도 복사되서 연산이 이루어진다. 1x3 과 3x1의 연산도 3x3으로 복사되서 된다. 브로드캐스팅 조건으로 연산을 위해 행이나 열의 크기의 최소공배수가 두 배열중 한 배열의 크기와 같아야한다. - Masking 비교연산자나 조건문으로 각 원소..
Numpy_Indexing, Slicing, Operator - Numpy Indexing, Slicing import numpy as np # 인덱싱 슬라이싱 lst = np.array([[1,2,3],[4,5,6],[7,8,9]]) slicing_lst = lst[:2,:2] print(slicing_lst) # [[1,2],[4,5]] print(lst[1]) # [4,5,6] 기본 문법과 동일하다. - Numpy Operator ## 연산 a = np.array([1,2,3]) b = np.array([4,5,6]) # 각 요소 더하기 c = a+b # c = add(a,b) print(c) # [5,7,9] # 각 요소 곱하기 np.multiply(a,b) print(a*b) # [4,10,18] # 각 요소 나누기 np.divide(a,b) print(..
Numpy_Create Array - Numpy란? 과학 계산을 위한 라이브러리 행렬/ 배열 처리 및 연산 난수생성 다차원 배열을 쉽게 처리하고 효율적으로 사용할 수 있도록 지원하는 Python의 Package 배열의 생성에 대해서 다뤄보자. import numpy as np a = [[1,2,3],[4,5,6]] b = np.array(a) print(b) # [[1,2,3],[4,5,6]] print(b.ndim) # 배열의 차원 print(b[0,0]) # b[0][0]과 똑같다. 기본적인 배열은 numpy.array()로 생성한다. 기존의 파이썬문법과 다르게 numpy는 2차원이상 인덱싱을 괄호 하나에 좌표형식으로 적어도 가능하게끔 지원해준다. ## 특수한 배열의 생성 lst1 = np.arange(10) print(lst1) #..
Class JavaScript는 프로토타입을 사용한 상속을 사용한다. // 기본적인 예제 function Vacation(destination, length) { this.destination = destination; this.length = length; } Vacation.prototype.print = function() { console.log(this.destination + "은(는)" + this.length + "일 걸립니다.") }; const maui = new Vacation("마우이", 7); maui.print(); class Vacation { constructor(destination, length) { this.destination = destination; this.length = ..
JavaScript for React 2 - 객체(Object)와 배열(Array) const sandwich = { bread: "더치 크런치", meat: "참치", cheese: "스위스", toppings: ["상추","토마토","머스타드"] }; const {bread, meat} = sandwich; console.log(bread, meat); // 더치 크런치 참치 위의 코드는 bread와 meat에 sandwich에 있는 같은 이름의 필드 값으로 초기화 된다. const lordify = reqularPerson => { console.log(`캔터베리의 ${reqularPerson.firstname}`); }; var reqularPerson = { firstname: "현석", lastname: "오" }; lordify(r..