Reputation: 273
Why do I get this error?
ufunc 'add' did not contain a loop with signature matching types dtype
The code:
cols = df.columns.tolist()
cols = np.array (cols)
cols2 = cols[:17] + cols[19:22] + cols [18]
Upvotes: 0
Views: 1892
Reputation: 1234
There are 2 issues
+
, when used on numpy
array, is interpreted as numerical addition, not list concatenation, thus the error about the matching dtype. Instead of addition, you should use np.concatenate
cols[18]
is not an array -- it is an element of the array. 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 = df.columns.tolist()
cols2 = cols[:17] + cols[19:22] + [cols[18]]
Upvotes: 1