결측치 처리, cross table, one-hot-encoding

seongyong·2021년 3월 17일
0

학습내용

결측치 처리

  1. 결측치 대체
df.fillna(value=0)
df.fillna(method = ' ') # method = 'bfill', 'pad' 등
df.replace(np.nan, 0)
df.interpolate(method = 'linear', limit_direction = 'forward') 
  1. 결측치 제거
df.dropna(axis =0, how= 'any')
#na가 있는 row를 전부 제거함
#thresh 설정으로 NaN이 속해있는 비율에 따라 제거 가능. ex) thresh = len(df)*0.9

Cross table

#두개의 variable(row, column)에 해당하는 데이터의 개수 설정 
pd.crosstable(df[row], df[columns])

one hot encoding

df = pd.get_dummies(data = df, columns = ['F1','F2','F6','F8','F9'])

0개의 댓글