-
파이썬 판다스 inplace 옵션파이썬(판다스, AI,데이터 분석) 2021. 5. 18. 17:01
inplace뜻은 '제자리에','가동할 준비가 되어 있는', '~을 위한 준비가 되어 있는' 라는 의미를 가지고 있다.
그렇다면 코딩에서 inplace는 어떤 의미를 가지고 있을까?
rename, drop등의 메서드를 사용할 때, 변경 값(변경될 데이터 프레임)을 저장 할 때 사용됩니다.
inplace = False (저장 안 함)
inplace = True (저장함)
drop('', axis ='' , inplace='' )
rename({},inplace ='')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersimport pandas as pd import numpy as np df = pd.DataFrame(data = np.array([[1,2,3,],[4,5,6],[7,8,9]]), columns =['A','B','C']) df df.drop('A', axis = 1, inplace =True) df df.drop('A', axis = 1, inplace =False) df inplace = True인 경우 원본 df의 메모리에 그래도 적용이된다. inplace = False인 경우 결과값은 drop 메서드가 적용되지 않는 df가 반환 됨을 볼 수 있다. 보통 코드 작성시에 inplace = False 를 사용하는 것이 실수를 줄일 수 있다고 한다.
적절하게 inplace 옵션을 사용하는 법을 익혀보자.
'파이썬(판다스, AI,데이터 분석)' 카테고리의 다른 글
판다스 인덱싱 (0) 2021.06.04 벡터와 매트릭스 ( Vectors and Matrices )-N131 (0) 2021.05.22 판다스(파이썬), 데이터 프레임, 행과 열 (0) 2021.05.18 판다스 한글 파일이 깨질 때 (0) 2021.05.15 [Pandas] csv(xlsx)파일 불러오기 (0) 2021.05.15