파이썬 데이터프레임 dataframe 특정 인덱스 행을 마지막으로 옮기기

728x90
index_name = "a"
temp = df.loc[index_name].copy() # 해당 인덱스 명으로 접근해서 복사
df.drop(index_name, inplace=True) # 기존 index_name 을 가진 행 삭제
df.loc[len(df)] = temp # 행 의 개수로 마지막 행에 temp를 추가
df.index.values[len(df) - 1] = "a" # index 명을 a로 변경
반응형