Numpy: Checking if a value is NaT

前端 未结 6 1653
余生分开走
余生分开走 2020-12-23 21:12
nat = np.datetime64(\'NaT\')
nat == nat
>> FutureWarning: In the future, \'NAT == x\' and \'x == NAT\' will always be False.

np.isnan(nat)
>> TypeError:         


        
6条回答
  •  春和景丽
    2020-12-23 21:54

    Since NumPy version 1.13 it contains an isnat function:

    >>> import numpy as np
    >>> np.isnat(np.datetime64('nat'))
    True
    

    It also works for arrays:

    >>> np.isnat(np.array(['nat', 1, 2, 3, 4, 'nat', 5], dtype='datetime64[D]'))
    array([ True, False, False, False, False,  True, False], dtype=bool)
    

提交回复
热议问题