Pandas 에서 가장 큰 혼동 source 는 원하는 row 와 column 어떻게 고를지. 라이브러리가 세 가지 indexing 스타일을 노출하고, 초보자가 그걸 머릿속에서 섞어서 에러 없이 틀린 답을 만들어. 작동하는 프레임워크 여기.
세 indexer
df['col']— label 로 column 접근. Series 반환.df.loc[row_label, col_label]— label 기반 selection. Row 와 column 둘 다 label (또는 boolean mask) 로 주소.df.iloc[row_pos, col_pos]— position 기반 selection. Row 와 column 둘 다 정수 position 으로 주소 — NumPy 배열처럼.
.loc 은 label 기반, .iloc 은 position 기반, 머릿속에서 절대 섞지 마. Legacy df.ix 는 사라졌어. Chained indexing 스타일 df[df.col > 0]['other'] = ... 는 SettingWithCopyWarning 의 전형적 source — Pandas 3.0 이 Copy-on-Write 의미 아래 그 나사를 더 죄었어.
Copy-on-Write 시대
Pandas 3.0 이 Copy-on-Write (CoW) 를 default 로. 실제 효과: 부모 DataFrame 을 조용히 mutate 하던 chained 할당이 이제는 copy 를 mutate 하거나 (변경이 사라짐) 명확한 에러 raise. 고치는 방법은 항상 같았어 — 할당 왼쪽에 row 와 column 둘 다 들어간 단일 .loc.