I have a tracts field (Tract) which I want to strip off the first 4 numbers in an attribute table. I created a new field (Tract2) for it. I've tried several commands without success using the field calculator. I'm receiving errors
It's not horrible if you come from a JS background, but I would agree that if you've got the option to use Python, it's usually the better choice. "Couldn't I just use Python for this?" is something I utter pretty frequently when I'm working with web layers.
Example also produced an error
Read the fine manual for the Calculate Field tool for more details on how to use the expression and code block.
Also if your tract is indeed a number (this is incorrect, you should try to get them read as text) you can string it to fix the problem, convert to string first, by wrapping the expression like this: f(str(!Tract!))
Make sure your Tract2 is a text field or you will lose leading zeros.
If your data are numbers, this Python expression should work without a code block. Assuming Tract2 is a text field, which it should be.
str(!Tract!)[4:]
That work accept it puts a .0 at the end. I need it without a .0 so I can join it with another table
str(!Tract!)[4:-2]
Can I ask where the original source of this data is? Did you by chance import a CSV or text file into Pro or something? It sounds an awful lot like a text-based data source being incorrectly interpreted as a number, which happens when a field only contains digits.
This is beyond the scope of the original question, but you may need to address upstream issues with how your data is imported. As @curtvprice notes, it really is supposed to be a text field.
Hrm. Can you confirm whether tract is coming in as a string or number? In any case, try explicitly changing it. Replace line 1 of the expression with this:
var t = Text($feature['Tract'])
The following work except it puts a .0 in at the end. I need it without the .0 so I can join it with another table.
If your data are numbers, this Python expression should work without a code block. Assuming Tract2 is a text field, which it should be.
str(!Tract!)[4:]
The original data source is numerical (double) so when I create a text field it puts .0 at the end. The data is a shape file. The .0 prevents me from joining it with the Census Tract data I downloaded. So, how can drop the .0 in the newly created text Tract Field from Python?