Python 3.x 如果数据框中的另一列中存在空值,我将尝试使用值更新新列

Python 3.x 如果数据框中的另一列中存在空值,我将尝试使用值更新新列,python-3.x,pandas,dataframe,Python 3.x,Pandas,Dataframe,如果列Report['BSD']为空,我正在尝试使用值“接口故障”更新列Report['Failure Reason']。报告是我的数据框架 我尝试了下面的代码,它抛出 “SyntaxError:关键字不能是表达式”错误 如果Report['BSD']为空,则应使用值更新列Report['Failure Reason']“接口故障”,否则应忽略它如果存在空字符串,则仅使用=: Report['Failure Reason'] = np.where(Report['BSD'] == '', 'In

如果列
Report['BSD']
为空,我正在尝试使用值
“接口故障”
更新列
Report['Failure Reason']
。报告是我的数据框架

我尝试了下面的代码,它抛出

“SyntaxError:关键字不能是表达式”错误


如果
Report['BSD']
为空,则应使用值
更新列
Report['Failure Reason']
“接口故障”
,否则应忽略它如果存在空字符串,则仅使用
=

Report['Failure Reason'] = np.where(Report['BSD'] == '', 'Interface Failure', ' ')
或者,如果缺少值,则通过以下方式进行测试:


np.where(Report['BSD']=“Interface Failure”,“Interface Failure””)
,您遗漏了
=
,而是放置了一个
=
,它没有进行比较!是的,谢谢!我错过了==。我再试了一次,但仍然没有发生,我不知道为什么。可能它们不是空字符串和NaNs intead,请检查下面@jezrael的答案
Report['Failure Reason'] = np.where(Report['BSD'] == '', 'Interface Failure', ' ')
Report['Failure Reason'] = np.where(Report['BSD'].isna(), 'Interface Failure', ' ')