본문 바로가기
Python/Pandas

[Python] Pandas DataFrame 인덱스 변경, 초기화 set_index(), reset_index()

by coding_su 2022. 11. 25.

📝파이썬 판다스 데이터 프레임 인덱스 변경, 초기화

df.set_index('컬럼') : 기존에 있는 컬럼의 값을 인덱스로 만든다

※ 뒤에 써준 inplace=True는 메모리 자체를 변경한다는 뜻

>>> df.set_index('컬럼')

# 메모리 자체를 변경할시
>>> df.set_index('컬럼', inplace=True)

df.reset_index() : 인덱스를 원래대로(컴퓨터가 매기는 인덱스) 초기화 시킨다

>>> df.reset_index()

댓글