如何在数据集中找到故障?

How to find glitch in the dataset?

现在,我面临一个问题,这里有一些包含故障的数据集。就像在数据集中有一个数字列。从外部可以很容易地识别出最大字段有数字。但它的数据类型是对象。不仅某些字段具有非数字值。
例如:
数据集有“Age”列:[23, 34, 54, 33, pp, 27, 43] 并且它的数据类型是对象。
现在,Chake this out it has a string value "pp" into the number value。我们称之为数据集中的故障。
现在我的问题是如何找到那些包含像“pp”这样的故障的行。

Here is an image of what I want to discuss with you

谢谢。

您可以使用 pd.to_numeric() with coercing errors (from non-numeric values) to NaN, and then check for NaN with isna()。然后,使用 .loc 找到具有这些 NaN 值(来自非数字值)的行:

df.loc[pd.to_numeric(df['Age'], errors='coerce').isna()]

演示

data = {"Age": [23, 34, 54, 33, 'pp', 27, 43] }
df = pd.DataFrame(data)

df.loc[pd.to_numeric(df['Age'], errors='coerce').isna()]

  Age
4  pp