python-3.x - 如果我的数据框中的另一列中有一个空值,我正在尝试用一个值更新一个新列
问题描述
如果列为空,我正在尝试Report['Failure Reason']
用值更新列。报告是我的数据框。"Interface Failure"
Report['BSD']
我尝试使用下面的代码,它抛出
“SyntaxError:关键字不能是表达式”错误
Report['Failure Reason'] = np.where(Report['BSD'] = '', 'Interface Failure', ' ')
如果Report['BSD']
为空,Report['Failure Reason']
则应使用 value 更新列"Interface Failure"
,否则应忽略
解决方案
如果有空字符串,==
仅使用:
Report['Failure Reason'] = np.where(Report['BSD'] == '', 'Interface Failure', ' ')
或者,如果有缺失值,请通过以下方式测试Series.isna
:
Report['Failure Reason'] = np.where(Report['BSD'].isna(), 'Interface Failure', ' ')
推荐阅读
- reactjs - 状态返回空数组
- javascript - 如何在从命令行运行时调试 js CLI 应用程序?
- c++ - 如何在包含数字 9 4 3 6 的 .bmp(二进制图像)中执行组件标记?
- kubernetes - 如果我想在 kubernetes 中使用 NodePort,如何知道节点中哪个端口可用
- javascript - 使用 Electron 重新加载后无法访问 SVG DOM
- python - 调用批处理文件从 VBA 运行 python 脚本
- php - 如何在 react-native 中从 php 向 android mobile 发送推送通知?
- c++ - 是否可以通过 PC 重新启动或用户单击应用程序快捷方式来确定 MFC 应用程序正在启动?
- android - 在android中实现MVVM时对网络层的错误处理感到困惑,如何通知用户有问题?
- python - Django:如何在 view.py 中获取客户端计算机用户名