-- python에 한정해서 (R 아님! 🤗) --
* None vs NaN(NA)
as of None...
☆ None is used to define a null value. It is not the same as an empty string, False, or a zero. It is a data type of the class NoneType object. Assigning a value of None to a variable is one way to reset it to its original, empty state.
→ 즉 None은 말그대로 missing data - 아무것도 없는, 데이터가 빠진 공간이라 생각하면 된다.
→ 함수가 아무것도 return하지 않으면 None을 return
→ NoneType object라는 특별한 type에 종속된다!
type(None) #NoneType
as of NaN... - numpy.nan
☆ None과 다르게 numerical operations 진행이 가능..! (NaN은 object type에 귀속되어 연산 내용에 포함되면 오류가 발생) numerically invalid하다 보면 됨(None은 empty인 반면)
→ NA type을 일률적으로 NaN으로 변환하여 표현
→ type이 float이므로 operation 진행이 가능한 것 (including vectorized operations)
import numpy as np
type(np.nan) #float
<<공식 explanation>>
"Additionally, it exacts a fairly high performance cost when working with numerical data compared with the simple approach of using NaN. Thus, I have chosen the Pythonic “practicality beats purity” approach and traded integer NA capability for a much simpler approach of using a special value in float and object arrays to denote NA, and promoting integer arrays to floating when NAs must be introduced."
☆ python에서 null은 존재하지 않음. null의 의미로 None과 NaN으로 표현
☆ isnull() & fillna() method 모두 None과 NaN에 적용 가능하다
df.isnull()
df.fillna()
** handling NaN - docu) https://pandas.pydata.org/pandas-docs/dev/user_guide/gotchas.html
** source) https://www.geeksforgeeks.org/python-none-keyword/
'Failures & Issues > problem-solution' 카테고리의 다른 글
SettingWithCopyWarning 해결법? (0) | 2022.04.13 |
---|---|
Q. Matplotlib graph 한글깨짐현상 & (-) 부호 해결법 (IDE - Jupyter Notebook) (0) | 2022.03.27 |
Q) NaN - dataframe 분포 그림으로 확인할 방법? (0) | 2022.03.23 |
댓글