TIL_6 : DataFrame Indexing

JaHyeon Gu·2021년 6월 28일
0

Data Science

목록 보기
6/16
post-thumbnail

💡 DataFrame Indexing이란?


DataFrame에서 원하는 데이터가 있는 부분을 선택하는 것!

👉 데이터 분석을 잘하고 자유자재로 하기 위해 중요


🙄 How to index

👉 df.loc['Row', 'Column']

Row 먼저 ❗❗❗❗


👉 Row, Column 값에 : 를 입력하거나 생략함으로써 한 Series 전체 출력 가능

👉 Series = Pandas의 1차원 자료형



🙄 여러 Row, Column Indexing

👉 list를 이용해 여러 행 or 열 Indexing

👉 type은 2차원 자료형인 DataFrame


👉 slicing을 이용해 여러 행 Indexing

👉 필요한 데이터가 연속적으로 위치할 때 사용


👉 열을 slicing 할 때는 좀 더 복잡



🙄 DataFrame 조건으로 Indexing

👉 boolean 값을 줌으로써 원하는 Row or Column을 출력


👉 Column 이름에 조건을 주고 Indexing


👉 조건이 여러개 일때

( ) & ( ) : 그리고,

( ) | ( ) : 또는



🙄 DataFrame 위치로 Indexing



🙄 DataFrame Indexing 문법


이름으로 Indexing기본 형태단축 형태
하나의 Rowdf.loc['row4']
여러 Rowdf.loc[['row4', 'row5', 'row3']]
여러 Row slicingdf.loc['row2':'row5']df['row2':'row5']
하나의 Columndf.loc[:, 'col1']df['col1']
여러 Columndf.loc[:, ['col4', 'col6', 'col3']]df[['col4', 'col6', 'col3']]
여러 Column slicingdf.loc[:, 'col2':'col5']

위치로 Indexing기본 형태단축 형태
하나의 Rowdf.iloc[8]
여러 Rowdf.iloc[[4, 5, 3]]
여러 Row slicingdf.iloc[2:5]df[2:5]
하나의 Columndf.iloc[:, 3]
여러 Columndf.iloc[:, [3, 5, 6]]
여러 Column slicingdf.iloc[:, 3:7]
profile
IWBAGDS

0개의 댓글