pd.read_sas错误:ufunc add不能使用类型为dtype('O')和dtype('<m8 [ns]')

时间:2017-11-17 15:46:30

标签: python pandas

=“”

我尝试仅在python中读取sas文件头:

df = pd.read_sas(sas_file, chunksize=0)

对于日期我收到错误的文件不起作用:

/anaconda/lib/python3.5/site-packages/pandas/io/sas/sasreader.py in read_sas(filepath_or_buffer, format, index, encoding, chunksize, iterator)
     59         return reader
     60 
---> 61     return reader.read()

/anaconda/lib/python3.5/site-packages/pandas/io/sas/sas7bdat.py in read(self, nrows)
    587         p.read(nrows)
    588 
--> 589         rslt = self._chunk_to_dataframe()
    590         if self.index is not None:
    591             rslt = rslt.set_index(self.index)

/anaconda/lib/python3.5/site-packages/pandas/io/sas/sas7bdat.py in _chunk_to_dataframe(self)
    632                 if self.convert_dates and (self.column_formats[j] == "MMDDYY"):
    633                     epoch = pd.datetime(1960, 1, 1)
--> 634                     rslt[name] = epoch + pd.to_timedelta(rslt[name], unit='d')
    635                 jb += 1
    636             elif self.column_types[j] == b's':

/anaconda/lib/python3.5/site-packages/pandas/core/ops.py in wrapper(left, right, name, na_op)
    649                 lvalues = lvalues.values
    650 
--> 651             return left._constructor(wrap_results(na_op(lvalues, rvalues)),
    652                                      index=left.index, name=left.name,
    653                                      dtype=dtype)

/anaconda/lib/python3.5/site-packages/pandas/core/ops.py in <lambda>(x, y)
    479 
    480                 # pass thru on the na_op
--> 481                 self.na_op = lambda x, y: getattr(x, self.name)(y)
    482                 return lvalues, rvalues
    483 

TypeError: ufunc add cannot use operands with types dtype('O') and dtype('<m8[ns]')

根据我的理解,它无法使用datetime转换列。 任何帮助将不胜感激。

0 个答案:

没有答案