일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 회귀
- 정렬
- 데이터베이스
- kmu
- 프로그래머스
- SQL
- programmers
- 운영체제
- Regression
- 재귀
- 머신 러닝
- LSTM
- instaloader
- Stack
- googleapiclient
- C++
- GIT
- Seq2Seq
- PANDAS
- 스택
- 파이썬
- Heap
- 국민대
- gan
- machine learning
- Python
- python3
- db
- OS
- 국민대학교
- Today
- Total
정리 노트
14일 차(2022/07/21) 본문
저번에는 pandas에서 NaN 값을 처리하는 방법을 배웠었습니다.
(Pandas에서 NaN 처리하기: 2022.07.17 - [[TIL]국민대X프로그래머스 여름방학 인공지능 과정] - 10일 차 (2020/07/17))
오늘은 numpy에서 NaN 값을 처리하는 방법을 배웠습니다.
isnan 통해 NaN 값 처리해보기
isnan은 numpy에서 제공하는 함수로, 각 요소마다 nan값인지 아닌지의 boolean 값을 담은 ndarray를 반환합니다.
import numpy as np
a = np.array([1, 2, np.nan, 3, 4, np.nan, np.nan, 5])
print(np.isnan(a))
# [False False True False False True True False]
이를 인덱싱에 활용해서 nan이 아닌 값들만을 추출해올 수 있습니다.
print(a[~np.isnan(a)]) # [1. 2. 3. 4. 5.]
isnan에 대한 추가적인 설명은 numpy document를 참고하시기 바랍니다.
https://numpy.org/doc/stable/reference/generated/numpy.isnan.html?highlight=isnan#numpy.isnan
numpy.isnan — NumPy v1.23 Manual
This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default
numpy.org
'[TIL]국민대X프로그래머스 여름방학 인공지능 과정' 카테고리의 다른 글
26일 차(2022/08/08) (0) | 2022.08.08 |
---|---|
19일 차(2022/07/28) (0) | 2022.07.28 |
11일 차(2022/07/18) (0) | 2022.07.18 |
10일 차 (2020/07/17) (0) | 2022.07.17 |
9일 차(2022/07/14) (0) | 2022.07.15 |