Python
[개미의 걸음 Pandas 9차시] 데이터 제거(drop)
IT개미 데이터
2021. 1. 9. 07:07
728x90
데이터 제거
컬럼 제거
데이터프레임명.drop(columns='제거할 컬러명', inplace=True)
데이터프레임명.drop('제거할 컬러명', axis=1, inplace=True)
- columns를 통해 제거하고 싶은 컬럼 지정
- axis=1을 지정하면 칼럼 삭제
→ axis =0을 지정하면 행(row) 삭제 - inplace=True를 통해 변경된 내용을 데이터 프레임에 저장
행 제거
데이터프레임명.drop(데이터프레임명[ 조건 ].index, inplace=True)
데이터프레임명.drop(제거할 인덱스명, axis=0, inplace=True)
- 해당 데이터프레임명에서 조건을 만족하는 행들만 제거
→ ex> titanic.drop(titanic[titanic['survived']==0].index, inplace=True) - 제거할 인덱스명을 입력하고 axis=0을 입력하면 해당 인덱스가 제거됨
→ 인덱스명이 임의의 인덱스명일 때 사용 [0,1,2, ..]
→ ex> titanic.drop(0, axis=0, inplace=True)
728x90