gpt4 book ai didi

python - 类型错误 : ufunc 'subtract' did not contain a loop with signature matching types dtype ('
转载 作者:行者123 更新时间:2023-12-01 07:07:46 26 4
gpt4 key购买 nike

我在减去数据表的两列时遇到问题,我是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')

最佳答案

看起来数据类型是字符串,尝试应用astype():

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

关于python - 类型错误 : ufunc 'subtract' did not contain a loop with signature matching types dtype ('<U8' ) dtype ('<U8' ) dtype ('<U8' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58361730/

26 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com