Tag Archives: apply

[Solved] ufunc ‘add‘ did not contain a loop with signature matching types (dtype(‘<U32‘), dtype(‘<U32‘))

Error type:
UFUNC 'Add' did not contain a loop with signature matching types (dtype ('& lt; U32'), dtype ('& lt; U32') - & gt; dtype('<U32')

The ‘Add’ function is a self-defined addition function. The error type is translated as: UFUNC ‘Add’ does not contain a loop with signature matching type. Check the error causes of others. Most of them are due to data type mismatch. The following add function will report this error when x is of type int and y is of type str.

def add(x,y):
    print(type(x))
    print(type(y))
    return x+y

Therefore, I added a function to view the data type in the add function, and found that the data type is:

<class 'numpy.float64'>
<class 'list'>

This confused me. I rechecked my function again

df1["property_grid"]=df1[["wgs84_lon","wgs84_lat"]].apply(lambda x: add( x["wgs84_lon"], ["wgs84_lat"]),axis=1)

It is found that an X is missing. The correct is as follows:

df1["property_grid"]=df1[["wgs84_lon","wgs84_lat"]].apply(lambda x: add( x["wgs84_lon"], x["wgs84_lat"]),axis=1)

Perfect solution~