I want to format a large number of fields in an attribute table so that they display with thousands separated by commas.
Is there any way to do this using python?
To do it via the GUI you would 1. display the attribute table, 2. right click on each field name, 3. select 'properties', 4. click on the '...' icon next to 'numeric', 5.click on 'show thousands separators' 6. select 'OK', 7. select 'OK' again.
I want to automate it so that the Python script would do this for all fields with an index number > 5 - that is, ignoring the first few fields which contain non-numeric data.
The reason I want to do this is that I want the field values to be displayed with thousands separators when they are displayed as labels in a map.
python allows that for strings in python 2.x,
but you will have to wait for python 3.6+ to get other options
So if you want your numbers to have commas, then you have to make a text/string field to put the expression in
In Python you don't have access to change the properties of how a field is displayed. You can update the contents of the field or create additional fields as Dan mentioned. In ArcMap you would need ArcObjects to do this. How many fields do you have?
That is a lot of fields... I can imagine that you don't want to do that manually. However, how are you going to present this to the "end-user" how are they going to use this data? Having 200 fields or more with data may not be the easiest way to use the data. Can you explain a little more about the use case and what type of data you have?
Adding the text fields (as per the suggestions by Dan and Joshua) can be scripted, but then you will end up with twice the amount of fields...
What you are after is IFieldInfo.NumberFormat Property (ArcObjects .NET 10.5 SDK). Unfortunately, Esri hasn't implemented that through ArcPy so the best you can do for now is either manually make the changes in the GUI or follow Dan's suggestion.
If there are 200 fields and more to come, I would strongly recommend that you have an alternate way for the client or you to 'view' the tabular information. Options would include
Multiple options, depending who the target audience is and how big a deal it is.