【发布时间】:2020-03-24 00:35:19
【问题描述】:
我想检查一个 Pandas 对象是否是/包含任何 Null/NaN/NaT 值,但如果该对象是一个列表还是一个奇异值,我事先没有任何信息。
我试过了
x = [1,2,3,pd.NaT]
if pd.notnull(x):
...
但是如果对象x是一个列表,它返回这个值错误(由于它返回一个布尔值数组):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
如果我这样做:
x = pd.NaT
if pd.notnull(x).any():
...
如果我收到一个奇异值,它会返回此错误:
AttributeError: 'bool' object has no attribute 'any'
能够处理可能包含 NaN 和 NaN 本身的两个列表的最干净的方法是什么?
【问题讨论】: