Programming Language/Pandas Library
[Python] 판다스 데이터프레임 인덱스명 변경, 컬럼명 변경(rename)
처카푸
2024. 4. 16. 12:25
인덱스 이름, 컬럼 이름을 변경하는 방법은 rename 함수를 사용한다
인덱스 명을 바꾸는 방법
- store3 를 last store로 변경해보자
df.rename( index= { 'store3' : 'last store' }, inplace=True )
df
컬럼 명을 바꾸는 방법
- bikes => hat, suits => shoes 으로 변경해 보자
df.rename( columns= { 'bikes':'hat', 'suits':'shoes' }, inplace=True )
df
새로운 컬럼을 만들고 벨류 값을 넣어주는 방법
- 새로운 컬럼 name 을 만들되, A, B, C 라고 넣자
df['name'] = ['A','B','C']
df