python - 根据条件将行更改为0
问题描述
我有一个数据框:
1 0 1 2
2 2 3 1
3 8 2 9
预期输出:
1 0 1 0
2 2 3 0
3 8 2 9
我最初的思考过程是
df = np.where(df['Reported'] >= df['Goal'], df['Score'] = 0, df['Score']
这不能按需要工作。
解决方案
您可以使用loc
索引方法:
df.loc[df['Reported'] >= df['Goal'],'Score'] = 0
推荐阅读
- php - 如何将带有翻译的记录添加到夹具 symfony
- flutter - Flutter:如何模块化底部导航栏
- vue.js - 输入字段值不断重置@input?
- django - 从带有 400 错误请求的 ajax 错误将数据发布到 DjangoRestFramework api
- c# - 在数据库中移动磁贴/文本框存储位置
- linux - 在 /usr/bin 中创建自定义命令不起作用
- python - 如何为 Django Tables2 使用 Django __str__() 方法
- matlab - MATLAB 中的 3D 海洋温度插值
- node.js - 将 NodeJS 和 NPM 更新到下一个版本?
- node.js - 如何格式化 JSON 字符串并包含图片?