반응형

Programming/Python 18

Python pandas 3강 - Nan 제거

Pandas는 NaN을 사용하여 행을 삭제합니다 이 자습서에서는 DataFrame.notna() 및 DataFrame.dropna() 메서드를 사용하여 NaN 값이있는 모든 행을 삭제하는 방법을 설명합니다. www.delftstack.com import pandas as pd import numpy as np from google.colab import drive drive.mount("/content/drive") df = pd.read_csv("/content/drive/MyDrive/Colab Notebooks/train.csv") # 연습 # 조건을 찾아보자 list_test = [ {"id":1,"password":1234,"age":20}, {"id":2,"password":1234,"age"..

Programming/Python 2021.10.26

Python pandas 2강 - DataFrame 사용

import pandas as pd import numpy as np from google.colab import drive drive.mount("/content/drive") df = pd.read_csv("/content/drive/MyDrive/Colab Notebooks/train.csv") - df.head() / df.tail() # 헤드보기 print(df.head(n=3)) print("="*50) # 꼬리보기 print(df.tail(n=2)) - df.sort_values(by="사용할 컬럼", ascending=False) # 컬럼으로 정렬하기 df.sort_values(by="Survived", ascending=False) - df.sort_index() # 안중요 df.sort..

Programming/Python 2021.10.26

Python pandas 1강 - 데이터 다루기

# 판다스 = 행렬 데이터(Matrix = 2차원) = 테이블 # 데이터(2차원)를 다루는 파이썬 라이브러리 import pandas as pd import numpy as np import matplotlib.pyplot as plt pandas.Series — pandas 1.3.4 documentation Values must be hashable and have the same length as data. Non-unique index values are allowed. Will default to RangeIndex (0, 1, 2, …, n) if not provided. If data is dict-like and index is None, then the keys in the data ar..

Programming/Python 2021.10.26

Python Numpy 7강 - 행렬곱, 연립방정식

# 브로드 캐스팅 복습 arr1 = np.array([1,2,3]) arr2 = np.array([[4,5,6],[7,8,9]]) # 스칼라 -> 원데이터 전체 변경 r1 = arr1 + [1] # +, /, *, - print(r1) print("="*50) # 같은모양 -> 원데이터 전체 변경 r2 = arr1 + arr2 print(r2) print("="*50) print(arr1.shape) print(arr2.shape) # 행 혹은 열의 크기가 같고 나머지가 1일 때 -> 원데이터 전체 변경 r3 = arr1 + arr2 print(r3) # 만약 전체를 변경하는 게 아니라 원하는 것 만 변경하려면 -> np.where을 쓰자 1. 행렬 곱 홍길동 - 공부!! - 하루일과중 효과적인 공부시간..

Programming/Python 2021.10.21

Python Numpy 6강 - BroadCasting

BroadCasting - 원데이터를 변경 - 스칼라(하나의 값으로 전체) - 같은모양(전체를 각각 변경 - 행만 같으면(행마다 다르게 변경) - boolean indexing -> np.where 사용 import numpy as np # 브로드 캐스팅은 배열의 요소끼리 연산(배열의 모양이 다른것들을) # 핵심 : 원데이터를 변경!! a = np.array([1,2,3]) b = np.array([2,2,2]) r1 = np.vstack((a,b)) print(r1) print("="*50) r2 = a+b print(r2) print("="*50) r3 = a+3 print(r3) print("="*50) r4 = a*[2] print(r4) print("="*50) # [1,2,3] (백터중에서는 ..

Programming/Python 2021.10.20

Python Numpy 5강 - DB연결, 학습

Numpy → DataFrame import pandas as pd from pandas import Series, DataFrame # 딕셔너리를 DataFrame으로 변경해도된다. fish_dataFrame = pd.DataFrame(fishs, columns=["fish_len", "fish_wei", "target"]) # 번호 넘버링을 미리하고 싶다면? print(fish_dataFrame) Visual Studio Code 사용 (1) numpy, pandas 라이브러리 설치 Visual Studio Code → Terminal pip install numpy pip install pandas (2) mariaDB에 넣기 ① DB 생성 - root로 접속 create user 'python'@..

Programming/Python 2021.10.20

Python Numpy 4강 - 데이터 합쳐서 시각화 하기

import numpy as np # stack 은 쌓아 올리다. (연산이 아니다) bream_length = [25.4, 26.3, 26.5, 29.0, 29.0, 29.7, 29.7, 30.0, 30.0, 30.7, 31.0, 31.0, 31.5, 32.0, 32.0, 32.0, 33.0, 33.0, 33.5, 33.5, 34.0, 34.0, 34.5, 35.0, 35.0, 35.0, 35.0, 36.0, 36.0, 37.0, 38.5, 38.5, 39.5, 41.0, 41.0] # 도미의 무게 bream_weight = [242.0, 290.0, 340.0, 363.0, 430.0, 450.0, 500.0, 390.0, 450.0, 500.0, 475.0, 500.0, 500.0, 340.0, 60..

Programming/Python 2021.10.20

Python Numpy 3강 - arange, zeros, ones

Numpy에 존재하는 다양한 함수들 NumPy 다양한 함수들 - Codetorial NumPy의 다양한 함수의 사용법에 대해 소개합니다. codetorial.net arange - 임의의 데이터를 만들 때 사용 # 넘파이가 가지고 있는 함수 import numpy as np arr1 = np.arange(10) print(arr1[:6]) print("="*50) arr2 = np.arange(5,10) print(arr2) print("="*50) arr3 = np.arange(1,10,2) print(arr3) print("="*50) arr4 = np.arange(1,11) print(arr4) print("="*50) arr5 = arr4.reshape((2,-1)) # 2차원 변환 print(a..

Programming/Python 2021.10.20

Python Numpy 2강 - Slicing

아래 코드를 Slicing을 사용하면 아주 간편하게 사용가능하다 p1 = [ [1.2], [3,4] ] p1[0][0] = 8 print(p1[0][0]) print("*"*50) row = 0 for i in p1: print(p1[row][0]) row = row + 1 * Slicing # 넘파이로 파이썬 리스트로 변환(타입) # 넘파이로 reshape (크기가 동일해야 한다) - vector -> matrix -> tensor # 2차원이든 3차원이든 전부다 1차원으로 변경하는 방법 = flatten # 넘파이 슬라이싱 [:,:], 스탭 [:,::2] import numpy as np temp1 = [ [1,2,3,4], [1,2,5,8] ] m1 = np.array(temp1) print(m1[..

Programming/Python 2021.10.20

Python Numpy 1강 - 배열

1. dtype 종류 Data type objects (dtype) — NumPy v1.21 Manual The generic hierarchical type objects convert to corresponding type objects according to the associations: Deprecated since version 1.19: This conversion of generic scalar types is deprecated. This is because it can be unexpected in a context such as arr.a numpy.org [파이썬 numpy] 배열 데이터타입 종류/정의/확인 [파이썬 numpy] 배열 데이터타입 종류/정의/확인 numpy 데이터타입 ..

Programming/Python 2021.10.20
반응형