최대 1 분 소요

  • sklearn.impute: 결측치 처리하는 모듈 simple imputer, KNN imputer, Missingindicator 등 있음
  • random.randn(m): 평균이0이고 표준편차가 1인 m개의 난수 형성
  • .round(x): 소수점 x자리까지 반올림
  • df.corr() : column간 상관계수 구하기
  • df.info(): column 정보확인
  • df.copy(): 복사
  • np.nan: 결측치 처리
  • .isnull(): 결측치-> True
  • .sum(): 개수
  • df2.isnull().any(axis=1) 해석 df2.isnull(): df2에서 nan이 있는 셀을 True로 표시 .any(axis=1): 어떠한 열이라도 True가 있는 행을 반환 즉 결과적으로 결측치가 있는 행 반환
  • df2.dropna(axis=0) : 결측치가 포함된 행 삭제
  • df2.loc[:, [‘age’, ‘measurement’]].fillna(-9999)
    age,measurement열의 결측치를 -9999로 치환
    문자열의 경우 unknown사용
  • df2.loc[:, [‘age’, ‘measurement’]].fillna(df2.mean()[[‘age’, ‘measurement’]-])
    결측치를 열 평균값으로 치환
  • df2.loc[:, [‘gender’, ‘education’]].fillna(df2.mode().iloc[0])
    mode(최빈값)을 활용하여 치환하기
    iloc[0]: 최빈값중 첫번째 사용
  • pd.to_datetime(): to_datetime 함수를 활용하여 str -> datetime으로 변환
  • date[n].dayofweek: 0~6까지 표시, 0:일요일, 1:월요일…
    df2[‘dayofweek’] = df2[‘date’].apply(lambda x: x.dayofweek)
    date에 dayofweek를 적용하여 dayofweek라는 열 추가
  • df2[‘date’] = pd.date_range(start=df2.date.min(), end=df2.date.max(), freq=’D’) :date 재정의, freq=’D’는 daily

카테고리:

업데이트:

댓글남기기