Python isnan - TypeError: Not implemented for this type

Python isnan - TypeError: Not implemented for this type

我有一个这样的列表:

 - 1 21      84.0104      
 -  2 22      81.9372      
 -  3 23          NaN      
 - 4 00          NaN          
 -  5 01      78.7023      
 -  6 02      80.0526  

在我的代码中,我试图用零替换所有 NaN。所以我使用了 Numpy isnan:

import pylab as pl
import numpy as np
from numpy import isnan

filename = "dataset"
file = open(filename)

data = []
for line in file:
    data.append(line.strip('\n').strip('\t').split(' '))
NaNs = np.isnan(data)                                                
data[NaNs] = 0 

但这对我不起作用,我收到错误消息:

"NaNs = np.isnan(数据)
TypeError:未针对此类型实现

我还尝试将模块 pandas 与:

集成
import pandas as pd

但这对我也不起作用。我只得到一个 "ImportError: No module named pandas"。任何人都可以帮助我理解和解决这个问题吗?谢谢!

如果输入的数据是一个字符串(看起来确实如此),您可能只需要使用:

line.replace("NaN", "0")

这应该将所有 NaN 替换为 0