반응형
DataFrame 셀 작업
행 및 열 레이블로 셀 선택
value = df.at['row', 'col']
value = df.loc['row', 'col']
value = df['col'].at['row']
행 및 열 레이블로 셀 설정
df.at['row', 'col'] = value
df.loc['row', 'col'] = value
df['col'].at['row'] = value
라벨 선택 및 자르기
df = df.loc['row1':'row3', 'col1':'col3']
라벨로 단면 설정
df.loc['A':'C', 'col1':'col3'] = np.nan
df.loc[1:2,'col1':'col2']=np.zeros((2,2))
df.loc[1:2,'A':'C']=othr.loc[1:2,'A':'C']
정수 위치로 셀 선택
value = df.iat[9, 3] # [row, col]
value = df.iloc[0, 0] # [row, col]
value = df.iloc[len(df)-1, len(df.columns)-1]
int 위치로 셀 범위 선택
df = df.iloc[2:4, 2:4] # subset of the df
df = df.iloc[:5, :5] # top left corner
s = df.iloc[5, :] # return row as Series
df = df.iloc[5:6, :] # returns row as row
정수 위치로 셀 설정
df.iloc[0, 0] = value # [row, col]
df.iat[7, 8] = value
정수 위치로 셀 범위 설정
df.iloc[0:3, 0:5] = value
df.iloc[1:3, 1:4] = np.ones((2, 3))
df.iloc[1:3, 1:4] = np.zeros((2, 3))
df.iloc[1:3, 1:4] = np.array([[1, 1, 1],
[2, 2, 2]])
혼합 라벨 및 정수 위치 인덱싱을 위한 .ix
value = df.ix[5, 'col1']
df = df.ix[1:5, 'col1':'col3']
참고 : https://www.geeksforgeeks.org/pandas-cheat-sheet
Pandas Cheat Sheet for Data Science in Python
This cheat sheet provides a quick reference to the most common Pandas commands, covering everything from data loading and manipulation to plotting and visualization. Whether you're a beginner or a seasoned data scientist, this cheat sheet is a valuable res
www.geeksforgeeks.org
반응형
'Python' 카테고리의 다른 글
python 판다스(pandas) 소개 및 기능 (0) | 2023.11.12 |
---|---|
python 판다스(pandas) DataFrame 합치기 merge joining groupby 작업 (0) | 2023.11.12 |
python 판다스(pandas) DataFrame rows 행 작업 (0) | 2023.11.12 |
python 판다스(pandas) DataFrame columns 열 작업 (0) | 2023.10.21 |
python 판다스(pandas) DataFrame 구조 통계 확인하기 (0) | 2023.10.21 |