空值運算
在處理遺漏資料時,通常會以空的型別來儲存這些遺漏值。如此一來,你就能更容易地識別、替換,或進一步操作它們!因此,我們會使用 None 與 numpy.nan 這兩種型別。你需要能清楚分辨兩者的差異。
在這個練習中,你將比較 None 與 numpy.nan 在進行算術與邏輯運算時的行為差異。numpy 已以 np 匯入。程式中使用了 try 與 except 區塊以避免錯誤。
本練習屬於課程
在 Python 中處理遺漏值
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
try:
# Print the sum of two None's
print("Add operation output of 'None': ", ___)
except TypeError:
# Print if error
print("'None' does not support Arithmetic Operations!!")