Home np.isfinite(pd.Series) vs (pd.Series).notna() 비교
Post
Cancel

np.isfinite(pd.Series) vs (pd.Series).notna() 비교

numpy.isfinite()와 pandas.Series.notna()가 어떤 값들을 확인해주는지 궁금해서 비교해보았습니다.

  1. numpy.isfinite()

    infinity가 아니고 NaN이 아닌 값에 대해서 True를 반환합니다.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
     np.isfinite(pd.Series([np.nan, np.inf, None, 0, 1, 100]))
    
     ->
    
     0    False
     1    False
     2    False
     3     True
     4     True
     5     True
     dtype: bool
    
  2. pandas.Series.notna()

    not NA인 값에 대해 True를 반환합니다.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
     pd.Series([np.nan, np.inf, None, 0, 1, 100]).notna()
    
     ->
    
     0    False
     1     True
     2    False
     3     True
     4     True
     5     True
     dtype: bool
    
  • pandas.Series.notna의 설명에 따르면 empty string이나 np.inf는 NA값으로 고려되지 않습니다.

    Characters such as empty strings “” or numpy.inf are not considered NA values (unless you set pandas.options.mode.use_inf_as_na = True). NA values, such as None or numpy.NaN, get mapped to False values.

This post is licensed under CC BY 4.0 by the author.