Needing Help with a Python Statement.

718
3
02-24-2012 07:37 AM
AndrewRoberts2
New Contributor III
Hey,

I have some data in ArcGIS that has a column in the attribute table for month. Right now it looks like 1, 2, 3, ... ,12. but I need it to look like 01, 02 , 03, ... , 12.

I figured the best way to do this, because i have a lot of data, would be to use calculate field and create a new field for month, with a python statement that would add a 0 to the front of any of the numbers with a length of one. I have yet to figure out a statment that would do this, I've tried many variations of !NewMonth! = '0' + !month!

Any help is apprecaited.

Thanks!
-Andrew
Tags (2)
0 Kudos
3 Replies
ChrisSnyder
Regular Contributor III
Check out this post: http://forums.arcgis.com/threads/50658-Iterate-with-leading-zeros

The field calculator expresion equivalent should be:

"str(!ORIG_MONTH!).zfill(2)"
0 Kudos
AndrewRoberts2
New Contributor III
Here is how I got this to work.
[ATTACH=CONFIG]15759[/ATTACH]
0 Kudos
FabianBlau
Occasional Contributor II
Another way:
r"%i/%02i" % (year, month)
0 Kudos