3

I try to build stacked label expression in ArcGis 10.3.1 with this expression:

[name3] + '\n'+ [results]

enter image description here

name3 and results are two columns in the attribute table. But I get this error:

typeerror coercing to unicode need string or buffer nonetype found

I read Building label expressions - Expression examples but didn't find any solution.

This is the attribute table:

enter image description here

enter image description here

  • 1
    Have you set to Python parser? – Martin Aug 22 '16 at 6:12
  • you're mixing your parsers.. with a vb parser you need to use vbNewLine: [name3] & vbNewLine & [results] or change to python parser. – Michael Stimson Aug 22 '16 at 6:19
  • Looks like you need to take a second look at what field types you are trying to merge. If not both are string, you might also need str(). – Martin Aug 22 '16 at 6:24
  • 1
    I think this part of the error nonetype found hints at what may be astray. I think there is at least one <null> value in one or other field and when the Python parser gets to that it says that it cannot concatenate a nonetype (i.e. a <null>). – PolyGeo Aug 22 '16 at 6:55
  • @PolyGeo I've been testing that, but I can't generate the same error when concatenating Nulls. I'm trying to figure how coercing to unicode need string comes into it here – Midavalo Aug 22 '16 at 6:57
7

A value in one (or both) of your fields is a number, and python is trying to add it due to the + symbol, or alternatively it could be a value that can't be handled in its current form. Either way you'll need to tell python that it's a string. It is currently trying to use the value as unicode and it needs a string.

Using the Python Parser you need to use:

"{}\n{}".format([name3], [results])

This will ensure that the values in your fields name3 and results are treated as string in the label, even if the fields contain numbers.

Alternatively, if you're using the VB Parser you could use:

[name3] & vbNewLine & [results]

Python Parser example:
enter image description here

VB Parser example:
enter image description here

4
str([name3]) + '\n'+ str([results])

Convert your attributes to strings before joining.

  • but both of the fields definite as string – newGIS Aug 22 '16 at 6:51
  • 1
    Did you try my answer? Did it work? – jbalk Aug 22 '16 at 6:52
  • it worked but i get also 'NONE' values in the lables – newGIS Aug 22 '16 at 6:59
  • 2
    To eliminate the None values, you could just update your table on all empty values with an empty string with 2 single quotes '' (not a double quote). They won't appear anymore. – gisnside Aug 22 '16 at 8:58
  • 1
    @newGIS - it may be because python is handling the null values as something other than a string. You're better off using VB for simple expressions like this one. – jbalk Aug 31 '16 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.