python - 如何报告熊猫数据框的所有数据上存在错误字符?
问题描述
在我的数据框上:
什么是浏览我的数据框数据的最简单方法是数字并检测类型字符:',“并报告它们?我们可以避免这个系列吗?
我想浏览我的数据框并检测值中存在的单引号和双引号,如果有的话,我只想显示一个 logging.error 与特定行上的字符存在。
示例 1:"Double quote are detected on R3 and R1"
示例 2:"Simple quote are detected on R2"
解决方案
你可以试试:
print('Single quote are detected on row(s): ', df.apply(lambda x: x.astype(str).str.contains("'")).any(axis=1)[lambda x: x].index.tolist())
print('Double quote are detected on row(s): ', df.apply(lambda x: x.astype(str).str.contains('"')).any(axis=1)[lambda x: x].index.tolist())
输出:
Single quote are detected on row(s): ['R2']
Double quote are detected on row(s): ['R1', 'R3']
推荐阅读
- batch-file - 我将如何通过批处理文件更改我的背景
- r - 如何在R中每天计算每个ID的实例?
- jquery - 在 Woocommerce 中的购物车更新中删除重复的 div
- selenium - 多个标签的xpath问题
- ios - 在 iOS 中将 NSData 转换为 Int 返回垃圾值
- javascript - 在 Vue 中,哪个 watcher 会先被调用?对物体的深度观察,还是对该物体的属性的观察?
- amazon-redshift - 使用 WHERE 子句时查询 redshift 会引发带有特殊字符的错误
- asp.net-core - 将 Serilog 与 ASP.NET Core 3.0 一起使用时,如何使用与根记录器不同的配置动态创建记录器?
- linux - 如何制作假的 USB 设备或使设备显示为另一个设备
- python - pycharm- 带有 selenium web 驱动程序的 python。获取错误对象没有属性驱动