空值的运算
在处理缺失数据时,您需要将这些缺失值存储为"空"类型。这样,您就能轻松识别、替换或对其进行操作!因此我们会使用 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!!")