简体   繁体   English

如何在数据集中找到毛刺?

[英]How to find glitch in the dataset?

Nowadays, I'm facing a problem that here have some datasets that contain glitches.现在,我面临一个问题,这里有一些包含故障的数据集。 Like in a dataset has a number column.就像在数据集中有一个数字列。 externally can easily be recognized that the maximum field has numbers.从外部可以很容易地识别出最大字段有数字。 But its datatype is Object.但它的数据类型是Object。 Not only that some of the fields have non-numeric values.不仅某些字段具有非数字值。
for example:例如:
A dataset has " Age " column: [23, 34, 54, 33, pp, 27, 43] and its datatype is object.一个数据集有“年龄”列: [23, 34, 54, 33, pp, 27, 43]并且它的数据类型是对象。
Now, Chake this out it has a string value " pp " into the number value.现在,Chake 这个它有一个字符串值“ pp ”到数字值中。 what we have known as a glitch in the dataset.我们所知道的数据集中的故障。
Now my question is how can I found those rows that contain the glitches like " pp ".现在我的问题是我怎样才能找到那些包含像“ pp ”这样的小故障的行。

Here is an image of what I want to discuss with you这是我想与您讨论的内容的图像

Thanks.谢谢。

You can use pd.to_numeric() with coercing errors (from non-numeric values) to NaN , and then check for NaN with isna() .您可以使用pd.to_numeric()为了胁迫错误(非数值),以NaN ,然后检查NaNisna() Then, use .loc to locate the row(s) with those NaN values (from non-numeric values):然后,使用.loc使用这些NaN值(来自非数字值)定位行:

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

Demo演示

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM