简体   繁体   中英

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. 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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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