None, Null, undefined, NaN, NA 구분

epiphany·2022년 10월 7일

개념 정리

목록 보기
2/2
post-thumbnail


해당 개념들 정의를 위해 찾을때 가장 많이 돌아다니는 짤 ㅋㅋ..

None

  • 아무것도 없는 데이터(Null을 의미)
  • python에서 Null, undefined를 None으로 통칭해서 사용하는 것 같음

undefined

  • 변수 선언만 되어있고 값이 할당되어 있지 않은 상태, type이 undefined임
  • python에서 undefined를 처리하는 방법은 except NameError를 사용하는 방법임

Null

  • 값이 있긴한데 의도적으로 비어있는 값, type이 object임

NaN(Not a Number)

  • 표현되지 않는 부동소수점 값, python에서는 float타입을 의미함
  • 잘못된 수식으로 인해 발생한 값
  • == 으로는 비교되지 않고 is를 사용해야함
test = NaN
print(test, type(test))

if test == NaN:
    print("test == NaN")
elif test is NaN:
    print("test is NaN")
else:
    print("test is not NaN")

💻 출력

nan <class 'float'>
test is NaN

NA: Not Available

  • R에서 잘못된 값을 의미함
test = NA
print(test, type(test))

if test == NA:  # TypeError: boolean value of NA is ambiguous
    print("test == NA")
elif test is NA:
    print("test is NA")
else:
    print("test is not NA")

💻 출력

<NA> <class 'pandas._libs.missing.NAType'>
# test == NA가 없다면 test is NA에 걸림

참고

profile
iamda.tistory.com 이사 중

0개의 댓글