ArcPy Update Cursor if/else

4686
15
Jump to solution
06-18-2019 03:27 PM
ModernElectric
Frequent Contributor

Good Afternoon:

     I have been doing multiple searches on how to correctly write an if/else statement using Update Cursor to update a specific field based on the criteria in a different field, and lets say I got nothing. 

    Looking for a little help on how to write this:

      I have a field called BILLING_MONTH_TEXT (text) and another field called BILLING_DATE (text).

What I need to do is say (As an Example) if BILLING_MONTH_TEXT is May-2019 then it would update BILLING_DATE with a value of 30. If it is April-2019, the value would be 29. And so on and so on. 

If I could get started, I can figure out how to fill in the remaining months and values.

Thank You for your help.

0 Kudos
15 Replies
ModernElectric
Frequent Contributor

The Convert Time Field tool is being used with a number of other tool(s) in a stand-alone python script that will later be combined into a batch file for easier processing. 

The code that I am using to convert the raw READING_DATE field to the text file is this:

      arcpy.ConvertTimeField_management(ELECTRIC_METER_READING_RAWDATA, "READING_DATE", "'Not Used'", "READING_DATE_CONVERT_TEXT", "TEXT", "MM/dd/yyyy;1033;;")

Last time I tried to run it with only about 8,000 rows, it took about 25 minutes to run. 

This is what it looks like when its finally done:

0 Kudos
JoeBorgione
MVP Emeritus

That's just a concept script; you'd need to take those elements and add them into an update cursor.

That should just about do it....
0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Taking a step back, are you looking to set the billing date on the second to last day of each month?

0 Kudos
ModernElectric
Frequent Contributor

I think I am being a little vague on what I am trying to do. I have a table of reading data (approx 15,000 records) of approx 30 months. I have one field that is the billing date (ex. May-2019). The other field is the billing month (ex. 30). Basically, I started with Dec-2016 which has a value of 1, Jan-2017 which is assigned a value of 2 and so on and so forth to May-2019. A previous step uses the Convert Date tool to get the May-2019. This step is to update the Billing Month field based on the value in the Billing Date field. 

Hope this helps and makes more sense.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

So effectively your final data would look something like:

BILL_DATEBILL_MONTH
Dec-20161
Dec-20161
Jan-2017

2

......
June-201819
......
June-201819
July-201820
......
May-201930
0 Kudos
ModernElectric
Frequent Contributor

Joshua:

   Yes, in a nut shell that would be correct. 

I have a series of Model(s) in ArcToolBox that runs my process for me (Billing Data) and it takes several hours to run the process. I am working on transitioning the model(s) to python scripts to make the process run faster and maybe run it automatically through a series of batch file(s). 

0 Kudos