TIL_7 : Data 변형

JaHyeon Gu·2021년 6월 29일
0

Data Science

목록 보기
7/16
post-thumbnail

🙄 How to change Data


간단 ❗ Indexing하고 원하는 값을 지정 해주면 끝


값을 list로 넘김으로써 한 Row, Column의 값을 한번에 바꿀 수 있다.


한 Data를 입력하면 모든 Data 통일!



🙄 How to change Data #2


여러 Column을 바꾸고 싶다면 list로 indexing


여러 Row도 마찬가지


조건을 이용한 indexing을 통해 True인 Data 변경 가능


위치 indexing을 통한 Data 변경

위 방법들은 원본 파일 유지! DataFrame만 변형!



🙄 How to insert & delete Data


➡ Insert

기존에 없던 Row 이름에 Data를 입력하면 새로운 Row가 생성된다.


Column도 마찬가지❗❗


➡ Delete

Row 삭제 = df.drop('Row', axis = 'index', inplace = False)
inplace =True : 원본에서도 삭제
inplace = False : 원본에 영향 X


Column 삭제 = df.drop('Column', axis = 'columns', inplace = True)


여러 Row를 삭제하고 싶다면 list로 넘겨주면 된다.




🙄 Index/Column 설정하기


Column 설정 : df.rename(columns = {'현재 이름':'바꾸고 싶은 이름'}, inplace = True)


여러 Column 변경 : 사전으로 값을 여러개 넘겨준다.


index 이름 설정 : df.index.name = '원하는 이름'


다른 Column을 index로 바꾸기 : df.set_index('원하는 Col', inplace = True)
❗❗ 기존 index는 날아가기 때문에 미리 다른 Column에 추가를 해줘야 한다.

profile
IWBAGDS

0개의 댓글