[英]ufunc 'add' did not contain a loop with signature matching types dtype
Why do I get this error?为什么我会收到这个错误?
ufunc 'add' did not contain a loop with signature matching types dtype ufunc 'add' 不包含签名匹配类型 dtype 的循环
The code:编码:
cols = df.columns.tolist()
cols = np.array (cols)
cols2 = cols[:17] + cols[19:22] + cols [18]
Thanks!谢谢!
There are 2 issues有2个问题
+
, when used on numpy
array, is interpreted as numerical addition, not list concatenation, thus the error about the matching dtype. +
,当在numpy
数组上使用时,被解释为数字加法,而不是列表连接,因此是关于匹配 dtype 的错误。 Instead of addition, you should use np.concatenate
np.concatenate
而不是加法cols[18]
is not an array -- it is an element of the array. cols[18]
不是数组——它是数组的一个元素。 You cannot add a number and a array (if what you want to do is to append the element to the array)cols2 = np.concatenate([cols[:17], cols[19:22], [cols[18]]])
or you can keep cols as a list (not converting it to numpy
array and use list addition):或者您可以将 cols 保留为列表(不将其转换为
numpy
数组并使用列表添加):
cols = df.columns.tolist()
cols2 = cols[:17] + cols[19:22] + [cols[18]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.