简体   繁体   English

AttributeError:导入SAS数据集时,“ bool”对象没有属性“ sum”

[英]AttributeError: 'bool' object has no attribute 'sum' while importing SAS dataset

I am importing a huge sas dataset of about 7 GB in Anaconda Spyder (Python 3.5) using pandas.read_sas. 我正在使用pandas.read_sas在Anaconda Spyder(Python 3.5)中导入大约7 GB的巨大sas数据集。 The code is something like as below: 该代码如下所示:

import pandas as pd
hugedata = pd.read_sas('K:/HugeData.sas7bdat')

but I received the following error: 但我收到以下错误:

Traceback (most recent call last):

  File "<ipython-input-46-31acb10b0e92>", line 1, in <module>
    hugedata = pd.read_sas('K:/ERA/Credit Risk Estimates/PRAM/NW_RM_SUB_FCLY_M_HIST.sas7bdat')

  File "C:\Users\l086276\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\sas\sasreader.py", line 61, in read_sas
    return reader.read()

  File "C:\Users\l086276\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\io\sas\sas7bdat.py", line 579, in read
    nd = (self.column_types == b'd').sum()

AttributeError: 'bool' object has no attribute 'sum'

Just wondering why internal call to sas7bdat.py function is generating error on importing this dataset while its working absolutely fine with other sas datasets. 只是想知道为什么内部调用sas7bdat.py的函数在导入此数据集时会生成错误,而它与其他sas数据集的关系却很好。 What could go wrong with this dataset. 该数据集可能会出什么问题。 Need help please. 请需要帮助。

I've found that the sas7bdat package works where the pandas fails with the above message. 我发现sas7bdat软件包在熊猫失败并显示上述消息的地方起作用。

from sas7bdat import SAS7BDAT

def load_sas(sasfile,
             encoding="utf8",
             encoding_errors="replace"):

    with SAS7BDAT(sasfile, encoding=encoding,encoding_errors=encoding_errors) as sas:
        sas = iter(sas)
        columns = [c for c in next(sas)]
        df = pd.DataFrame(sas, columns=columns)
        return df

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

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