python - 如何检查数据框列是否包含数值?蟒蛇 3.6
问题描述
我有两列的数据框 - REGIONID & REGIONNAME
如果 REGIONID 包含数字值,我想用 REGIONNAME 更新 REGIONID。
Data_All.loc[Data_All['REGIONID'].str.isnumeric() is True , 'REGIONID'] = Data_All['REGIONNAME']
我收到类似的错误
"KeyError: 'cannot use a single bool to index into setitem'"
解决方案
删除is True
因为isnumeric
返回布尔掩码:
Data_All.loc[Data_All['REGIONID'].str.isnumeric(), 'REGIONID'] = Data_All['REGIONNAME']
如有必要,请检查True
s(例如NaN
,列中的 s REGIONID
):
Data_All.loc[Data_All['REGIONID'].str.isnumeric() == True, 'REGIONID'] = Data_All['REGIONNAME']
推荐阅读
- python - python 2.7重命名列表中的值
- r - 应用于分组数据框中的组的两个日期之间的工作日数
- excel - 如何在 Excel 工作簿选项卡中创建宏以打开 MS Project 并复制参考单元格
- sequelize.js - 雪花云数据库是否有任何 Sequelize 驱动程序?
- c# - 向远程 WebDriver 服务器发送 HTTP 请求以获取 URL,引发了具有空响应的异常
- reactjs - 如何从公共文件夹 reactjs create-react-app 加载 css & js
- bash - 试图将我的 sudo 命令转换为 bash 脚本
- javascript - 是否可以在 d3 墨卡托地图中有很大的区域可以悬停/触摸以显示工具提示?
- python - 如何将 for 循环应用于 os.path.join()
- html - Bootstrap html不同的字体和样式内联