[AI Bootcamp] N113 - Data Manipulation

HYUNG JIN·2021년 7월 12일
0

AI Bootcamp

목록 보기
3/17
post-thumbnail

Session Review

Data Manipulation

데이터 합치기

Concat(Concatenate): 이어 붙이기

  • '+'연산자 사용
  • tostring
  • join
    ❓ table JOIN:

pd.concat([x, y]) # concate by row
pd.concat([x, y], axis = 1) # concate by column

Merge: 공통된 부분을 기반으로 합치기
DataFrame.merge(붙일 내용, how='방법', on= 공통의 column or index(기준 feature))

Conditioning

필터링 조건 설정하기

condition = (df['순이익률'] > 0) # 조건 ()로 씌우는 것
condition = ((df['순이익률'] > 0) & (df['순이익률'] < 10))
# &(and) |(or) 사용하여 여러 개 condition 동시 설정 가능

df_subset = df[condition] 
# [] 안에 컨디션 설정 -> 컨디션 값이 *TRUE*로 해당하는 부분의 데이터만 선택

isin
Groupby

Tidy 데이터

라이브러리에 따라 다른 데이터 필요 e.g. Seaborn 라이브러리(시각화)는 대부분 "Tidy" 데이터 필요로 함
Tidy: 한 행(row)에 한 observation, Column에는 value 지정
Melt: wide -> tidy
pivot_table

# index: unique identifier
# columns: "wide" 데이터에서 column별로 다르게 하고자 하는 값.
# values: 결과값이 들어가는 곳 (wide 데이터프레임의 내용에 들어갈 값)
wide = tidy1.pivot_table(index = 'row', columns = 'column', values = 'value')

Assignment

한글 폰트 깨짐

!sudo apt-get install -y fonts-nanum
!sudo fc-cache -fv
!rm ~/.cache/matplotlib -rf


%matplotlib inline 
import matplotlib.pyplot as plt

plt.rc('font', family='NanumBarunGothic')

index 새로 지정

df.set_index('index로 지정할 feature')

profile
Always stay confident

0개의 댓글