AttributeError:'TextFileReader'对象没有属性'get_chunck'

时间:2013-12-02 17:01:54

标签: python pandas

我正在尝试使用pandas get_csv函数懒惰地阅读一个巨大的文件。我想访问指定列的前5000个元素。但我收到了我在标题中提到的错误。

#fetching data 
train = pd.read_csv(os.path.join(dir,"Train.csv"),iterator = True)

test = pd.read_csv(os.path.join(dir,"Test.csv"),iterator = True)

获取我需要的部分数据:

labels = np.array(train.get_chunk(5000))[:,3]
train = np.array(train.get_chunck(5000))[:,2]
test = np.array(test.get_chunk(5000))[:,2]

错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-43-b164e8752510> in <module>()
      1 labels = np.array(train.get_chunk(5000))[:,3]
----> 2 train = np.array(train.get_chunck(5000))[:,2]
      3 test = np.array(test.get_chunk(5000))[:,2]

AttributeError: 'TextFileReader' object has no attribute 'get_chunck'

显然我不允许这样做吗?如果没有,我怎么能重写这个以实现我想用这个代码实现的目标?

3 个答案:

答案 0 :(得分:4)

get_chunck拼写错误!

答案 1 :(得分:2)

尝试使用get_chunk代替get_chunck

答案 2 :(得分:1)

get_chunck是罪魁祸首! get_chunk