python 中未检测到 csv 中的空单元格

Empty cell in csv not detected in python

我已经在使用 .isna.isnull 检查数据中的缺失值,结果表明数据中没有缺失值。但是当我使用 excel 浏览数据时,我发现一列中有几个空单元格。该列应该具有数字数据类型,但由于它有几个空单元格而被识别为对象。如果我想删除这些单元格,我该怎么办?

That column was supposed to have numerical data type, but it got identified as object because it has several empty cells.

这表明它们是空字符串,''。您可以使用 replace:

将它们替换为 NaN 值
df = df.replace('', np.nan)