首页 > 解决方案 > 如何报告熊猫数据框的所有数据上存在错误字符?

问题描述

在我的数据框上:

在此处输入图像描述

什么是浏览我的数据框数据的最简单方法是数字并检测类型字符:',“并报告它们?我们可以避免这个系列吗?

我想浏览我的数据框并检测值中存在的单引号和双引号,如果有的话,我只想显示一个 logging.error 与特定行上的字符存在。

示例 1:"Double quote are detected on R3 and R1"

示例 2:"Simple quote are detected on R2"

标签: pythonpython-3.xpandasdataframe

解决方案


你可以试试:

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']

推荐阅读