언빌리버블티
[Python] Pandas interpolate() : 보간법을 활용한 결측치 처리 본문
✅ Interpolate 보간법을 통한 결측치 처리
DataFrame.interpolate(method='linear', *, axis=0, limit=None, inplace=False,
limit_direction=None, limit_area=None, downcast=None, **kwargs)
- 가장 간단한 선형보간법 (linear interpolation)이 default로 제공
- NaN값에 대해 가장 단순한 선형 회귀를 사용하여 데이터를 채워넣는다.
- 그 외에도 cubic, polynomial, 가장 가까운 값을 가져다 쓰는 nearest 등등을 사용한다.
- 시계열 데이터에서 가장 많이 사용 - 이전이나 이후값으로 대체
- NaN값에 대해 가장 단순한 선형 회귀를 사용하여 데이터를 채워넣는다.
- 특정 컬럼(column)만 보간법(interpolation)을 사용하고 싶다면, 데이터 프레임 전체 대신 특정 컬럼만 써주면 된다.
import pandas as pd
dates = ['10/23/2022','10/24/2022','10/25/2022',
'10/26/2022','10/27/2022']
dates = pd.to_datetime(dates)
df = pd.Series([62, np.nan, np.nan, 158, 189], index = dates)
df = df.interpolate()
2022-10-23 62.0
2022-10-24 94.0
2022-10-25 126.0
2022-10-26 158.0
2022-10-27 189.0
dtype: float64
'Language > Python' 카테고리의 다른 글
[Python] Pandas 시리즈 접근자 ( dt. str. cat. sparse. ) (0) | 2022.10.12 |
---|---|
[Python] Pandas List를 이용한 요소 필터링 - pd.isin() (0) | 2022.10.12 |
[Python] Pandas data type을 숫자로 변환하기 - pd.to_numeric() (0) | 2022.10.12 |
[Python] Pandas 데이터프레임 조건 탐색 및 대치 메서드 pd.where 과 np.where 차이 (0) | 2022.10.11 |
[Python] Pandas Dataframe 누적합과 누적곱 구하기 - pd.cumsum() / pd.cumprod() (0) | 2022.10.11 |
Comments