如何在Python中将pandas DataFrame与None进行比较?

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从不使用相等运算符.

还有一个很好的解释原因.