TypeError:ufunc'subtract'不包含签名匹配类型为dtype('<U8')dtype('<U8')dtype('<U8')

时间:2019-10-13 08:15:39

标签: python pandas

我在减去数据表的两列时遇到麻烦,我是python的新手,在尝试研究如何解决此问题失败之后,我想知道是否有人对此有所了解。我的代码是这样的:

response = qc.query(token, sql=query, fmt='pandas')
result = Table.from_pandas(response)
g_r   =result['dered_mag_g'] - result['dered_mag_r']
r_z   = result['dered_mag_r'] - result['dered_mag_z']

这是我得到的错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-13-836ed65f38bb> in <module>()
----> 1 g_r   =result['dered_mag_g'] - result['dered_mag_r']
      2 r_z   = result['dered_mag_r'] - result['dered_mag_z']
/data0/sw/anaconda2/lib/python2.7/site-packages/numpy/ma/core.pyc in __sub__(self, other)
   4083         if self._delegate_binop(other):
   4084             return NotImplemented
-> 4085         return subtract(self, other)
   4086
   4087     def __rsub__(self, other):
/data0/sw/anaconda2/lib/python2.7/site-packages/numpy/ma/core.pyc in __call__(self, a, b, *args, **kwargs)
   1016         with np.errstate():
   1017             np.seterr(divide='ignore', invalid='ignore')
-> 1018             result = self.f(da, db, *args, **kwargs)
   1019         # Get the mask for the result
   1020         (ma, mb) = (getmask(a), getmask(b))

TypeError: ufunc 'subtract' did not contain a loop with signature matching types dtype('S8') dtype('S8') dtype('S8')

1 个答案:

答案 0 :(得分:1)

似乎dtypes是字符串,请尝试应用astype():

g_r=result['dered_mag_g'].astype(float) - result['dered_mag_r'].astype(float)