0

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.

aaron
  • 39,695
  • 6
  • 46
  • 102
Mr Moose
  • 3
  • 1
  • 5
  • Have you tried encoding and stripping the string like in this example? https://stackoverflow.com/questions/9942594/unicodeencodeerror-ascii-codec-cant-encode-character-u-xa0-in-position-20 – Michael Platt Nov 22 '17 at 14:37
  • The string `'CHARTRIDGE'` is plain ASCII, there's no `'\udc43'` there. I suspect that there's something wrong with the way you're reading your data, or the data itself is corrupt. It's hard to say without a [mcve]. FWIW, `'\udc43'` is a ["low surrogate"](https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates). As the link mentions, surrogates are used in UCS and they _must_ occur in pairs. – PM 2Ring Nov 22 '17 at 14:42
  • Thanks for that, I've just given it a look and its gone above my head I'm afraid. I'm new to python, been stuck on this for a few hours today. – Mr Moose Nov 22 '17 at 14:42
  • In an effort to help, could you post the contents of the `LOCARY`? Could you also include some more of the stack trace? Maybe anything that says where in your program's execution the error was thrown? – Michael Platt Nov 22 '17 at 14:46
  • Hi there, yes LOCARY has the output array(['CHARTRIDGE', 'PIDDINGTON ROAD', 'WOODLANDS', ..., 'TONTINE FARM', 'NICKLE COTTAGES', 'WADE FARM'], dtype=' – Mr Moose Nov 22 '17 at 19:39

0 Answers0