如何在Python中将pandas DataFrame与None进行比较?
如何将pandas数据帧与如何在Python中将pandas DataFrame与None进行比较?,python,pandas,python-2.x,nonetype,Python,Pandas,Python 2.x,Nonetype,如何将pandas数据帧与None进行比较?我有一个构造函数,它接受参数_文件或参数_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
None
进行比较?我有一个构造函数,它接受参数_文件
或参数_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
但是,当我稍后尝试将pandas_-df
与None
进行比较时(即self.pandas_-df
实际包含pandas数据帧时):
我得到以下类型错误:
File "C:\Anaconda1\lib\site-packages\pandas\core\internals.py", line 885, in eval
% repr(other))
TypeError: Could not compare [None] with block values
使用
不是
:
if self.pandas_df is not None:
print 'Do stuff'
说:
应始终使用is
或is not
来比较像None
这样的单例,而不要使用相等运算符
还有一个很好的理由
if self.pandas_df is not None:
print 'Do stuff'