Cia*_*lsh 26 python python-2.x pandas nonetype
如何比较pandas DataFrame None
?我有一个构造函数,它接受一个parameter_file
或一个pandas_df
但从不两个.
def __init__(self,copasi_file,row_to_insert=0,parameter_file=None,pandas_df=None):
self.copasi_file=copasi_file
self.parameter_file=parameter_file
self.pandas_df=pandas_df
Run Code Online (Sandbox Code Playgroud)
但是,当我稍后尝试比较pandas_df
反对None
时(即self.pandas_df
实际包含pandas数据帧时):
if self.pandas_df!=None:
print 'Do stuff'
Run Code Online (Sandbox Code Playgroud)
我得到以下TypeError:
File "C:\Anaconda1\lib\site-packages\pandas\core\internals.py", line 885, in eval
% repr(other))
TypeError: Could not compare [None] with block values
Run Code Online (Sandbox Code Playgroud)
Mik*_*ler 50
用途is not
:
if self.pandas_df is not None:
print 'Do stuff'
Run Code Online (Sandbox Code Playgroud)
PEP 8说:
与单身人士的比较
None
应始终使用is
或者is not
从不使用相等运算符.
还有一个很好的解释原因.
归档时间: |
|
查看次数: |
15216 次 |
最近记录: |