nat = np.datetime64('NaT')
nat == nat
>> FutureWarning: In the future, 'NAT == x' and 'x == NAT' will always be False.
np.isnan(nat)
>> TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
如何檢查datetime64是否爲NaT?我似乎無法從文檔中挖出任何內容。我知道熊貓可以做到這一點,但我寧願不添加一個如此基本的東西的依賴。Numpy:檢查值是否爲NaT
你可以用'np.datetime64(「納特)'實際的比較:'NAT == np.datetime64( 'NaT')'輸出:'正確'。 –
你使用的是1.11.1嗎? NaTs不能再進行比較:https://github.com/numpy/numpy/blob/master/doc/release/1.11.0-notes.rst – user65
我很抱歉,這是我的注意力不集中。 1.現在你可以比較'nat == nat'並且它會返回'True'。 2.正如github所說,在'numpy 1.12.0'中,你仍然可以比較'NaT':'nat!= np.datetime64('NaT')'將返回'True',否則所有的比較涉及NaT將返回False。所以,最後的結論是:首先你需要檢查numpy的版本,然後選擇如何比較'NaT'。 –