I am trying to take two separate columns of data and create a stacked label where the bottom line (Benzen_1Q_2019) will be red and a larger font, while the top line (Well_ID) will be a dark grey color and a smaller font. I have symbolized the labels already and am now working on using Python to change the color and the font size. I have gotten the majority of it done, but the one thing I am struggling with is the column (text field) I am using for the second line (Benzen_1Q_2019) has values that are either a whole number or (-) or <1. When I type out out the Python expression, it works correctly for the values that are either (-) or a whole number, but it does not work for the values that are <1.

Any tips for how to make this work correctly?

My expression:

[Well_ID] + '\n' + "<CLR red ='255'><FNT size ='7'>" + [Benzen_1Q_2019] + "</FNT></CLR>"

Attribute Table Python code and labels]2


Per the Label Expression help, the < (less than) character is being evaluated as part of the expression. Thus your labels get confused.

You can do an inline replace on the the less than:

[Well_ID] + '\n' + "<CLR red ='255'><FNT size ='7'>" + [Benzen_1Q_2019].replace("<", "&lt;") + "</FNT></CLR>"

There are other approaches (see the previously mentioned doc)

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.