본문 바로가기

DataScience90

Pandas 행, 열 추가, 데이터 삭제 drop(), rename(), 인덱스 초기화 reset_index(inplace= True) In [66]: [ {'bikes': 20, "pants" : 30, "watches" : 35, "glasses" : 4} ] Out[66]: [{'bikes': 20, 'pants': 30, 'watches': 35, 'glasses': 4}] In [67]: new_item = [ {'bikes': 20, "pants" : 30, "watches" : 35, "glasses" : 4} ] In [68]: pd.DataFrame(data = new_item, index = ["store 3"]) Out[68]: bikes pants watches glasses store 3 20 30 35 4 In [69]: new.. 2022. 11. 24.
Pandas .iloc[ , ], 데이터 프레임에서 컬럼 만드는 방법 Accessing Elements in Pandas DataFrames¶ In [1]: import pandas as pd In [2]: # We create a list of Python dictionaries items2 = [{'bikes': 20, 'pants': 30, 'watches': 35}, {'watches': 10, 'glasses': 50, 'bikes': 15, 'pants':5}] In [8]: df = pd.DataFrame(data=items2, index= ["store 1","store 2"]) In [9]: df Out[9]: bikes pants watches glasse.. 2022. 11. 24.
Pandas Dataframe, Nan의 의미, 데이터프레임 엑세스 Pandas Dataframe¶ 레이블로 생성하기¶ In [1]: import pandas as pd # We create a dictionary of Pandas Series items = {'Bob' : pd.Series(data = [245, 25, 55], index = ['bike', 'pants', 'watch']), 'Alice' : pd.Series(data = [40, 110, 500, 45], index = ['book', 'glasses', 'bike', 'pants'])} In [2]: # 판다스의 2차원 데이터 처리는, # 데이터 프레임으로 한다. # 데.. 2022. 11. 23.
Pandas Series, 레이블과 인덱스, Operations PYTHON PROGRAMMING FUNDAMENTALS¶ Pandas 의 장점¶ Allows the use of labels for rows and columns 기본적인 통계데이터 제공 NaN values 를 알아서 처리함. (not a number, 비어있는 데이터) 숫자 문자열을 알아서 로드함. 데이터셋들을 merge 할 수 있음. (합친다) It integrates with NumPy and Matplotlib In [2]: import pandas as pd Pandas Series 데이터 생성하기¶ In [3]: index = ['eggs', 'apples', 'milk', 'bread'] data = [30, 6, 'Yes&#.. 2022. 11. 23.
Numpy Slicing 주의점, Copy, boolean 연산 Slicing 할때, 주의할 점!!!!¶ In [329]: X[ 0:1+1 , 0:2+1] Out[329]: array([[84, 41, 74], [77, 92, 40]]) In [330]: Y = X[ 0:1+1 , 0:2+1] In [331]: Y Out[331]: array([[84, 41, 74], [77, 92, 40]]) In [332]: Y[0,0] = 100 In [333]: Y Out[333]: array([[100, 41, 74], [ 77, 92, 40]]) In [334]: X Out[334]: array([[100, 41, 74, 55, 32], [ 77, 92, 40, 91, 26], [ 52, 7, 46, 13, 50], [ 67, 76, 86, 70, 100]]) In [33.. 2022. 11. 23.
Numpy 인덱스접근, 슬라이싱 In [223]: # X 에, 70보다 큰 데이터는 몇개인가? In [224]: X Out[224]: array([[84, 41, 74, 55, 32], [77, 92, 40, 91, 26], [52, 7, 46, 13, 50], [67, 76, 86, 70, 65]]) In [233]: X > 70 Out[233]: array([[ True, False, True, False, False], [ True, True, False, True, False], [False, False, False, False, False], [False, True, True, False, False]]) In [234]: (X > 70).sum() # True = 1 False = 0 이므로. Out[234]: 7 In [2.. 2022. 11. 23.
Numpy random, sum, mean, max, min, axis PYTHON PROGRAMMING FUNDAMENTALS¶ 다음 토픽을 다룹니다.: Numpy 기초 Built-in methods and functions shape, length and type of Numpy arrays Reshape Minimum and maximum Mathematical Operations Indexing and slicing Selection NUMPY BASICS¶ NumPy는 다차원 배열을 처리할 수 있는 선형대수학(Linear Algebra) 라이브러리입니다. 다음이 실행이 안되면 아나콘다프롬프트에서 conda install numpy 를 실행하여 설치합니다. In [2]: # numpy : 데이터를 효율적으로 저장 할 수 있는 data structure # pandas.. 2022. 11. 23.
파이썬에서 함수 실행시 메모리의 상태 2022. 11. 22.
Python 라이브러리 datetime(날짜,시간 처리) In [124]: # 날짜 처리 In [125]: from datetime import date # 데이트타임 파일 안에 데이트를 가져와라 [만든사람마음] In [126]: '2022-05-08' Out[126]: '2022-05-08' In [129]: date(2022, 5, 8) Out[129]: datetime.date(2022, 5, 8) In [130]: some_day = date(2022, 5, 8) # 데이터 처리를 위해 변수에저장 In [133]: some_day.year # 속성 Out[133]: 2022 In [134]: some_day.month Out[134]: 5 In [135]: some_day.day Out[135]: 8 In [136]: som.. 2022. 11. 22.
Python 라이브러리 random In [29]: import random In [1]: random.random() #임포트 하기전에 실행했을 경우 에러. --------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In [1], line 1 ----> 1 random.random() NameError: name 'random' is not defined In [8]: random.random() Out[8]: 0.4687911568655634 Random number : 난수 생성하기¶ 0.0 ~ 1.0 사이 난수 생성¶ In [3]: random.random.. 2022. 11. 22.
Python 4.함수 PYTHON PROGRAMMING FUNDAMENTALS¶ 다음 토픽을 다룹니다. : Functions Lambda Expressions Map In [ ]: # 함수는, 영어변수명같은거 오른쪽에 바로 소괄호로() 시작하면, 함수다. In [2]: # 함수의 호출 (function call) len('hello') Out[2]: 5 In [4]: a = 'hello' In [6]: # 타입함수를 호출( function call) type(a) Out[6]: str In [7]: b = [100, 33, 20] In [9]: # 함수의 호출 b.append(1) In [10]: # 지금까지 여러분들이 사용한것은 ?? 함수의 호출을 한것 # 어딘가에는 함수의 실체(함수의 정의 d.. 2022. 11. 21.
Python 3.반복문 A)For PYTHON PROGRAMMING FUNDAMENTALS¶ 우리가 배울것 : 반복문 - Loop¶ For Loops Break a loop Continue statement Range While Loops Nested loops List Comprehension 실행 순서에 대한 문법을 배웁시다.¶ In [1]: score = [90, 45, 77, 83, 39] In [7]: score[0] -5 Out[7]: 85 In [8]: score[1]-5 Out[8]: 40 In [11]: new_score = [score[0]-5, score[1]-5] In [12]: new_score Out[12]: [85, 40] In [ ]: #데이터 스트럭쳐에 저장된 데이터를 처음부터 끝가지 다 가져와서 작업하고 .. 2022. 11. 18.