【发布时间】:2016-03-06 21:53:41
【问题描述】:
我有一个这样的列表:
- 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:没有名为 pandas 的模块”。谁能帮我理解和解决这个问题?谢谢!
【问题讨论】:
-
No module named pandas消息表示您没有安装 pandas 包!
标签: regex file python-2.7 numpy nan