본문 바로가기

Python53

python 판다스(pandas) 소개 및 기능 "판다스(Pandas)의 필수 노하우: 데이터 분석가들이 매료된 핵심 기능" 소개: 데이터 분석 및 조작을 위한 파이썬의 핵심 라이브러리 중 하나인 판다스(Pandas)는 수많은 데이터 열성들에게 사랑받고 있습니다. 이 블로그에서는 데이터 분석가들이 가장 선호하는 판다스의 핵심 기능을 살펴보고, 어떻게 이러한 기능을 최대한 활용할 수 있는지 알아보겠습니다. 판다스의 핵심 기능: 데이터프레임과 시리즈: 판다스의 핵심은 데이터프레임(DataFrame)과 시리즈(Series)라는 두 가지 주요 데이터 구조에 있습니다. 데이터프레임은 행과 열로 이루어진 이차원 테이블이며, 시리즈는 라벨이 붙은 일차원 배열입니다. 이러한 구조를 통해 데이터를 효율적으로 저장하고 조작할 수 있습니다. 데이터 정제 및 전처리: 판다.. 2023. 11. 12.
python 판다스(pandas) DataFrame 합치기 merge joining groupby 작업 DataFrame 결합/그룹화 인덱스 병합 df_new = pd.merge(left=df1, right=df2, how='outer', left_index=True, right_index=True) df_new = df1.join(other=df2, on='col1', how='outer') df_new = df1.join(other=df2,on=['a','b'], how='outer') 열 병합 df_new = pd.merge(left=df1, right=df2, how='left', left_on='col1', right_on='col2') Concatenation 으로 병합 df=pd.concat([df1,df2],axis=0)#top/bottom df = df1.append([df2, df3]) .. 2023. 11. 12.
python 판다스(pandas) DataFrame 셀 cells 작업 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.. 2023. 11. 12.
python 판다스(pandas) DataFrame rows 행 작업 DataFrame rows 작업 행 인덱스 및 레이블 가져오기 idx = df.index # get row index label = df.index[0] # first row label label = df.index[-1] # last row label l = df.index.tolist() # get as a list a = df.index.values # get as an array (행) 인덱스 변경 df.index = idx # new ad hoc index df = df.set_index('A') # col A new index df = df.set_index(['A', 'B']) # MultiIndex df = df.reset_index() # replace old w new # note: o.. 2023. 11. 12.
반응형