UnicodeEncodeError: 'utf-8' codec can't encode character '\udc43' in position 1: surrogates not allowed

Mr Moose picture Mr Moose · Nov 22, 2017 · Viewed 8k times · Source

I have a list containing placenames and I want to create another array, initially empty, and then iterate the list of placenames and fill up my empty array with these placenames.

For example, my first location is 'CHARTRIDGE' and accessing this element in my LOCARY list via LOCARY[S[0][0]] I get: 'CHARTRIDGE'

I created an empty array: LOCLIST = np.empty([len(LOCARY),1])

I then wrote a for loop to fill it up with the items from LOCARY using:

for i in range(len(LOCARY)):
    LOCLIST[i] = LOCARY[S[i][0]]

But I get the error:

UnicodeEncodeError: 'utf-8' codec can't encode character '\udc43' in position 1: surrogates not allowed

I'm wondering if it doesn't like the characters ' in the placename.

Any help would be appreciated, thank you.

Answer