Converting none to zero (0) in geodatabase table using ArcPy?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












2















I have an attribute table looks like this



enter image description here



How do I convert Nulls into 0?



I've tried to set this table non nullable type but got this:



enter image description here



while the official doc says this:



enter image description here



At least one of them is wrong.



Then I tried many ways to do the job, like this:



RValues=arcpy.SearchCursor(sr)

for RValue in RValues:
#print (RValue.getValue(field))
if RValue.getValue(field) == None:
#print (RValue.getValue(field))
return 0
else
return
float(RValue.getValue(field))

print(RValue.getValue(field))


This gives error 999999, don't know why, possible a bug.



Then I tried this:



RValues=arcpy.SearchCursor(sr)
print (RValues)

for RValue in RValues:
if RValue.getValue(field) == None:
print (RValue.getValue(field))
arcpy.CalculateField_management(sr, "RValue", esp, "PYTHON3")
print (RValue.getValue(field))


Well, the first print gives a



<geoprocessing cursor object object at 0x0000025F5C161E70>


the second print does isolate all none items, as there is no null in python.



Here is the trick:



the third print either gives error or turn everything into null or 0,focus on everything, expressions I use are as follows:



esp="!RValue!.replace(None, 0)"

esp2="!RValue! * 0"

esp3="set field = 0 where field is null"

esp4="NVL(RValue,0)"

esp5="select nvl(RValue, 0) from sr.RValue"

esp6="None"


How is that even possible when the if before it already isolate only those nones?










share|improve this question
























  • also I've tried RValue.setValue(field,0) , also error 99999.

    – Karl Tian
    Jan 4 at 2:57











  • so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.

    – Karl Tian
    Jan 4 at 2:59






  • 1





    Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?

    – Andy
    Jan 4 at 3:21






  • 1





    Marking it as a duplicate won't delete the question or the answers, it just links them together so anyone that stumbles on this from Google or elsewhere will see the other question as well.

    – Evil Genius
    Jan 4 at 14:30















2















I have an attribute table looks like this



enter image description here



How do I convert Nulls into 0?



I've tried to set this table non nullable type but got this:



enter image description here



while the official doc says this:



enter image description here



At least one of them is wrong.



Then I tried many ways to do the job, like this:



RValues=arcpy.SearchCursor(sr)

for RValue in RValues:
#print (RValue.getValue(field))
if RValue.getValue(field) == None:
#print (RValue.getValue(field))
return 0
else
return
float(RValue.getValue(field))

print(RValue.getValue(field))


This gives error 999999, don't know why, possible a bug.



Then I tried this:



RValues=arcpy.SearchCursor(sr)
print (RValues)

for RValue in RValues:
if RValue.getValue(field) == None:
print (RValue.getValue(field))
arcpy.CalculateField_management(sr, "RValue", esp, "PYTHON3")
print (RValue.getValue(field))


Well, the first print gives a



<geoprocessing cursor object object at 0x0000025F5C161E70>


the second print does isolate all none items, as there is no null in python.



Here is the trick:



the third print either gives error or turn everything into null or 0,focus on everything, expressions I use are as follows:



esp="!RValue!.replace(None, 0)"

esp2="!RValue! * 0"

esp3="set field = 0 where field is null"

esp4="NVL(RValue,0)"

esp5="select nvl(RValue, 0) from sr.RValue"

esp6="None"


How is that even possible when the if before it already isolate only those nones?










share|improve this question
























  • also I've tried RValue.setValue(field,0) , also error 99999.

    – Karl Tian
    Jan 4 at 2:57











  • so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.

    – Karl Tian
    Jan 4 at 2:59






  • 1





    Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?

    – Andy
    Jan 4 at 3:21






  • 1





    Marking it as a duplicate won't delete the question or the answers, it just links them together so anyone that stumbles on this from Google or elsewhere will see the other question as well.

    – Evil Genius
    Jan 4 at 14:30













2












2








2








I have an attribute table looks like this



enter image description here



How do I convert Nulls into 0?



I've tried to set this table non nullable type but got this:



enter image description here



while the official doc says this:



enter image description here



At least one of them is wrong.



Then I tried many ways to do the job, like this:



RValues=arcpy.SearchCursor(sr)

for RValue in RValues:
#print (RValue.getValue(field))
if RValue.getValue(field) == None:
#print (RValue.getValue(field))
return 0
else
return
float(RValue.getValue(field))

print(RValue.getValue(field))


This gives error 999999, don't know why, possible a bug.



Then I tried this:



RValues=arcpy.SearchCursor(sr)
print (RValues)

for RValue in RValues:
if RValue.getValue(field) == None:
print (RValue.getValue(field))
arcpy.CalculateField_management(sr, "RValue", esp, "PYTHON3")
print (RValue.getValue(field))


Well, the first print gives a



<geoprocessing cursor object object at 0x0000025F5C161E70>


the second print does isolate all none items, as there is no null in python.



Here is the trick:



the third print either gives error or turn everything into null or 0,focus on everything, expressions I use are as follows:



esp="!RValue!.replace(None, 0)"

esp2="!RValue! * 0"

esp3="set field = 0 where field is null"

esp4="NVL(RValue,0)"

esp5="select nvl(RValue, 0) from sr.RValue"

esp6="None"


How is that even possible when the if before it already isolate only those nones?










share|improve this question
















I have an attribute table looks like this



enter image description here



How do I convert Nulls into 0?



I've tried to set this table non nullable type but got this:



enter image description here



while the official doc says this:



enter image description here



At least one of them is wrong.



Then I tried many ways to do the job, like this:



RValues=arcpy.SearchCursor(sr)

for RValue in RValues:
#print (RValue.getValue(field))
if RValue.getValue(field) == None:
#print (RValue.getValue(field))
return 0
else
return
float(RValue.getValue(field))

print(RValue.getValue(field))


This gives error 999999, don't know why, possible a bug.



Then I tried this:



RValues=arcpy.SearchCursor(sr)
print (RValues)

for RValue in RValues:
if RValue.getValue(field) == None:
print (RValue.getValue(field))
arcpy.CalculateField_management(sr, "RValue", esp, "PYTHON3")
print (RValue.getValue(field))


Well, the first print gives a



<geoprocessing cursor object object at 0x0000025F5C161E70>


the second print does isolate all none items, as there is no null in python.



Here is the trick:



the third print either gives error or turn everything into null or 0,focus on everything, expressions I use are as follows:



esp="!RValue!.replace(None, 0)"

esp2="!RValue! * 0"

esp3="set field = 0 where field is null"

esp4="NVL(RValue,0)"

esp5="select nvl(RValue, 0) from sr.RValue"

esp6="None"


How is that even possible when the if before it already isolate only those nones?







arcpy field-calculator python-parser error-999999 null






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 8 at 6:06









PolyGeo

53.3k1779238




53.3k1779238










asked Jan 4 at 2:51









Karl TianKarl Tian

134




134












  • also I've tried RValue.setValue(field,0) , also error 99999.

    – Karl Tian
    Jan 4 at 2:57











  • so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.

    – Karl Tian
    Jan 4 at 2:59






  • 1





    Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?

    – Andy
    Jan 4 at 3:21






  • 1





    Marking it as a duplicate won't delete the question or the answers, it just links them together so anyone that stumbles on this from Google or elsewhere will see the other question as well.

    – Evil Genius
    Jan 4 at 14:30

















  • also I've tried RValue.setValue(field,0) , also error 99999.

    – Karl Tian
    Jan 4 at 2:57











  • so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.

    – Karl Tian
    Jan 4 at 2:59






  • 1





    Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?

    – Andy
    Jan 4 at 3:21






  • 1





    Marking it as a duplicate won't delete the question or the answers, it just links them together so anyone that stumbles on this from Google or elsewhere will see the other question as well.

    – Evil Genius
    Jan 4 at 14:30
















also I've tried RValue.setValue(field,0) , also error 99999.

– Karl Tian
Jan 4 at 2:57





also I've tried RValue.setValue(field,0) , also error 99999.

– Karl Tian
Jan 4 at 2:57













so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.

– Karl Tian
Jan 4 at 2:59





so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.

– Karl Tian
Jan 4 at 2:59




1




1





Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?

– Andy
Jan 4 at 3:21





Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?

– Andy
Jan 4 at 3:21




1




1





Marking it as a duplicate won't delete the question or the answers, it just links them together so anyone that stumbles on this from Google or elsewhere will see the other question as well.

– Evil Genius
Jan 4 at 14:30





Marking it as a duplicate won't delete the question or the answers, it just links them together so anyone that stumbles on this from Google or elsewhere will see the other question as well.

– Evil Genius
Jan 4 at 14:30










2 Answers
2






active

oldest

votes


















4














In your second version, you've mixed cursors and CalculateField_management(). They don't work together in this way. CalculateField_management() will change the value for ALL RECORDS*, and pays no attention to what is happening in your cursor.



You should use either an UpdateCursor (NOT a SearchCursor) OR use a CalculateField_management(). Not both.



I usually do this sort of thing with just a CalculateField_management().
You can do this in one of two ways:



OPTION 1:



This is quicker than OPTION 2 below (but I posted 2 first, so will leave it there as is). This method only updates the records that need changing and also requires fewer lines. I think it is somewhat easier to read too.



Firstly, either select just the records that you want to change to '0' OR make a feature layer that only includes those records. I prefer the latter, as I feel safer (in the case the select doesn't work, you'll change ALL records; in the case the new feature layer doesn't work, you'll just get an error).



Then change all selected/layer records.



It's merely two lines:



arcpy.MakeFeatureLayer_management(sr, "srLayer", "RValue IS NULL")
arcpy.CalculateField_management("srLayer", "RValue", "0", "PYTHON")


Although you may like to clean up afterwards by deleting the layer with a third line:



arcpy.Delete_management("srLayer")


OPTION 2:



Include a code block which will determine the correct value for all records. Note that this will update records that don't need to be changed, but it will update them with the same value they already have, so not a big deal.



But this means that it is slower than OPTION 1 and also not as good for auditing purposes (eg, if you use editor tracking!).



codeblock = """
def calcRValue(rvalue):
if rvalue is None:
return 0
else:
return rvalue
"""
arcpy.CalculateField_management(sr, "RValue", "calcRValue(!RValue!)", "PYTHON", codeblock)


OTHER NOTES:



Don't use arcpy.SearchCursor or arcpy.UpdateCursor, which have been superceded. Use arcpy.da.SearchCursor or arcpy.da.UpdateCursor. They are massively faster (even if marginally more difficult syntax).



I'm not sure what your first version is trying to do, but the last line (print) uses the variable RValue out of scope and I would not expect it to work there. Perhaps it should be indented to be within the loop to print the value each time around the loop? But I'm not sure what it's supposed to be doing there.



*actually, all selected records if there are any, or all records otherwise.






share|improve this answer

























  • thank you, that just solve my problem

    – Karl Tian
    Jan 4 at 3:59











  • You're welcome. :-)

    – Son of a Beach
    Jan 4 at 4:02












  • that print there is to check the final result

    – Karl Tian
    Jan 4 at 5:13


















3














I prefer to use an UpdateCursor to manipulate feature class attributes. However, make sure to use the modern Data Access da cursors. For example:



import arcpy

fc = r'C:pathtoyourgeodatabase.gdbfeatureclass'

with arcpy.da.UpdateCursor(fc, "some_field") as cursor:
for row in cursor:
if row[0] == None: # None appears as <Null> in attribute table float fields
row[0] = 0
cursor.updateRow(row)





share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "79"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307543%2fconverting-none-to-zero-0-in-geodatabase-table-using-arcpy%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    In your second version, you've mixed cursors and CalculateField_management(). They don't work together in this way. CalculateField_management() will change the value for ALL RECORDS*, and pays no attention to what is happening in your cursor.



    You should use either an UpdateCursor (NOT a SearchCursor) OR use a CalculateField_management(). Not both.



    I usually do this sort of thing with just a CalculateField_management().
    You can do this in one of two ways:



    OPTION 1:



    This is quicker than OPTION 2 below (but I posted 2 first, so will leave it there as is). This method only updates the records that need changing and also requires fewer lines. I think it is somewhat easier to read too.



    Firstly, either select just the records that you want to change to '0' OR make a feature layer that only includes those records. I prefer the latter, as I feel safer (in the case the select doesn't work, you'll change ALL records; in the case the new feature layer doesn't work, you'll just get an error).



    Then change all selected/layer records.



    It's merely two lines:



    arcpy.MakeFeatureLayer_management(sr, "srLayer", "RValue IS NULL")
    arcpy.CalculateField_management("srLayer", "RValue", "0", "PYTHON")


    Although you may like to clean up afterwards by deleting the layer with a third line:



    arcpy.Delete_management("srLayer")


    OPTION 2:



    Include a code block which will determine the correct value for all records. Note that this will update records that don't need to be changed, but it will update them with the same value they already have, so not a big deal.



    But this means that it is slower than OPTION 1 and also not as good for auditing purposes (eg, if you use editor tracking!).



    codeblock = """
    def calcRValue(rvalue):
    if rvalue is None:
    return 0
    else:
    return rvalue
    """
    arcpy.CalculateField_management(sr, "RValue", "calcRValue(!RValue!)", "PYTHON", codeblock)


    OTHER NOTES:



    Don't use arcpy.SearchCursor or arcpy.UpdateCursor, which have been superceded. Use arcpy.da.SearchCursor or arcpy.da.UpdateCursor. They are massively faster (even if marginally more difficult syntax).



    I'm not sure what your first version is trying to do, but the last line (print) uses the variable RValue out of scope and I would not expect it to work there. Perhaps it should be indented to be within the loop to print the value each time around the loop? But I'm not sure what it's supposed to be doing there.



    *actually, all selected records if there are any, or all records otherwise.






    share|improve this answer

























    • thank you, that just solve my problem

      – Karl Tian
      Jan 4 at 3:59











    • You're welcome. :-)

      – Son of a Beach
      Jan 4 at 4:02












    • that print there is to check the final result

      – Karl Tian
      Jan 4 at 5:13















    4














    In your second version, you've mixed cursors and CalculateField_management(). They don't work together in this way. CalculateField_management() will change the value for ALL RECORDS*, and pays no attention to what is happening in your cursor.



    You should use either an UpdateCursor (NOT a SearchCursor) OR use a CalculateField_management(). Not both.



    I usually do this sort of thing with just a CalculateField_management().
    You can do this in one of two ways:



    OPTION 1:



    This is quicker than OPTION 2 below (but I posted 2 first, so will leave it there as is). This method only updates the records that need changing and also requires fewer lines. I think it is somewhat easier to read too.



    Firstly, either select just the records that you want to change to '0' OR make a feature layer that only includes those records. I prefer the latter, as I feel safer (in the case the select doesn't work, you'll change ALL records; in the case the new feature layer doesn't work, you'll just get an error).



    Then change all selected/layer records.



    It's merely two lines:



    arcpy.MakeFeatureLayer_management(sr, "srLayer", "RValue IS NULL")
    arcpy.CalculateField_management("srLayer", "RValue", "0", "PYTHON")


    Although you may like to clean up afterwards by deleting the layer with a third line:



    arcpy.Delete_management("srLayer")


    OPTION 2:



    Include a code block which will determine the correct value for all records. Note that this will update records that don't need to be changed, but it will update them with the same value they already have, so not a big deal.



    But this means that it is slower than OPTION 1 and also not as good for auditing purposes (eg, if you use editor tracking!).



    codeblock = """
    def calcRValue(rvalue):
    if rvalue is None:
    return 0
    else:
    return rvalue
    """
    arcpy.CalculateField_management(sr, "RValue", "calcRValue(!RValue!)", "PYTHON", codeblock)


    OTHER NOTES:



    Don't use arcpy.SearchCursor or arcpy.UpdateCursor, which have been superceded. Use arcpy.da.SearchCursor or arcpy.da.UpdateCursor. They are massively faster (even if marginally more difficult syntax).



    I'm not sure what your first version is trying to do, but the last line (print) uses the variable RValue out of scope and I would not expect it to work there. Perhaps it should be indented to be within the loop to print the value each time around the loop? But I'm not sure what it's supposed to be doing there.



    *actually, all selected records if there are any, or all records otherwise.






    share|improve this answer

























    • thank you, that just solve my problem

      – Karl Tian
      Jan 4 at 3:59











    • You're welcome. :-)

      – Son of a Beach
      Jan 4 at 4:02












    • that print there is to check the final result

      – Karl Tian
      Jan 4 at 5:13













    4












    4








    4







    In your second version, you've mixed cursors and CalculateField_management(). They don't work together in this way. CalculateField_management() will change the value for ALL RECORDS*, and pays no attention to what is happening in your cursor.



    You should use either an UpdateCursor (NOT a SearchCursor) OR use a CalculateField_management(). Not both.



    I usually do this sort of thing with just a CalculateField_management().
    You can do this in one of two ways:



    OPTION 1:



    This is quicker than OPTION 2 below (but I posted 2 first, so will leave it there as is). This method only updates the records that need changing and also requires fewer lines. I think it is somewhat easier to read too.



    Firstly, either select just the records that you want to change to '0' OR make a feature layer that only includes those records. I prefer the latter, as I feel safer (in the case the select doesn't work, you'll change ALL records; in the case the new feature layer doesn't work, you'll just get an error).



    Then change all selected/layer records.



    It's merely two lines:



    arcpy.MakeFeatureLayer_management(sr, "srLayer", "RValue IS NULL")
    arcpy.CalculateField_management("srLayer", "RValue", "0", "PYTHON")


    Although you may like to clean up afterwards by deleting the layer with a third line:



    arcpy.Delete_management("srLayer")


    OPTION 2:



    Include a code block which will determine the correct value for all records. Note that this will update records that don't need to be changed, but it will update them with the same value they already have, so not a big deal.



    But this means that it is slower than OPTION 1 and also not as good for auditing purposes (eg, if you use editor tracking!).



    codeblock = """
    def calcRValue(rvalue):
    if rvalue is None:
    return 0
    else:
    return rvalue
    """
    arcpy.CalculateField_management(sr, "RValue", "calcRValue(!RValue!)", "PYTHON", codeblock)


    OTHER NOTES:



    Don't use arcpy.SearchCursor or arcpy.UpdateCursor, which have been superceded. Use arcpy.da.SearchCursor or arcpy.da.UpdateCursor. They are massively faster (even if marginally more difficult syntax).



    I'm not sure what your first version is trying to do, but the last line (print) uses the variable RValue out of scope and I would not expect it to work there. Perhaps it should be indented to be within the loop to print the value each time around the loop? But I'm not sure what it's supposed to be doing there.



    *actually, all selected records if there are any, or all records otherwise.






    share|improve this answer















    In your second version, you've mixed cursors and CalculateField_management(). They don't work together in this way. CalculateField_management() will change the value for ALL RECORDS*, and pays no attention to what is happening in your cursor.



    You should use either an UpdateCursor (NOT a SearchCursor) OR use a CalculateField_management(). Not both.



    I usually do this sort of thing with just a CalculateField_management().
    You can do this in one of two ways:



    OPTION 1:



    This is quicker than OPTION 2 below (but I posted 2 first, so will leave it there as is). This method only updates the records that need changing and also requires fewer lines. I think it is somewhat easier to read too.



    Firstly, either select just the records that you want to change to '0' OR make a feature layer that only includes those records. I prefer the latter, as I feel safer (in the case the select doesn't work, you'll change ALL records; in the case the new feature layer doesn't work, you'll just get an error).



    Then change all selected/layer records.



    It's merely two lines:



    arcpy.MakeFeatureLayer_management(sr, "srLayer", "RValue IS NULL")
    arcpy.CalculateField_management("srLayer", "RValue", "0", "PYTHON")


    Although you may like to clean up afterwards by deleting the layer with a third line:



    arcpy.Delete_management("srLayer")


    OPTION 2:



    Include a code block which will determine the correct value for all records. Note that this will update records that don't need to be changed, but it will update them with the same value they already have, so not a big deal.



    But this means that it is slower than OPTION 1 and also not as good for auditing purposes (eg, if you use editor tracking!).



    codeblock = """
    def calcRValue(rvalue):
    if rvalue is None:
    return 0
    else:
    return rvalue
    """
    arcpy.CalculateField_management(sr, "RValue", "calcRValue(!RValue!)", "PYTHON", codeblock)


    OTHER NOTES:



    Don't use arcpy.SearchCursor or arcpy.UpdateCursor, which have been superceded. Use arcpy.da.SearchCursor or arcpy.da.UpdateCursor. They are massively faster (even if marginally more difficult syntax).



    I'm not sure what your first version is trying to do, but the last line (print) uses the variable RValue out of scope and I would not expect it to work there. Perhaps it should be indented to be within the loop to print the value each time around the loop? But I'm not sure what it's supposed to be doing there.



    *actually, all selected records if there are any, or all records otherwise.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 4 at 3:49

























    answered Jan 4 at 3:17









    Son of a BeachSon of a Beach

    1,413618




    1,413618












    • thank you, that just solve my problem

      – Karl Tian
      Jan 4 at 3:59











    • You're welcome. :-)

      – Son of a Beach
      Jan 4 at 4:02












    • that print there is to check the final result

      – Karl Tian
      Jan 4 at 5:13

















    • thank you, that just solve my problem

      – Karl Tian
      Jan 4 at 3:59











    • You're welcome. :-)

      – Son of a Beach
      Jan 4 at 4:02












    • that print there is to check the final result

      – Karl Tian
      Jan 4 at 5:13
















    thank you, that just solve my problem

    – Karl Tian
    Jan 4 at 3:59





    thank you, that just solve my problem

    – Karl Tian
    Jan 4 at 3:59













    You're welcome. :-)

    – Son of a Beach
    Jan 4 at 4:02






    You're welcome. :-)

    – Son of a Beach
    Jan 4 at 4:02














    that print there is to check the final result

    – Karl Tian
    Jan 4 at 5:13





    that print there is to check the final result

    – Karl Tian
    Jan 4 at 5:13













    3














    I prefer to use an UpdateCursor to manipulate feature class attributes. However, make sure to use the modern Data Access da cursors. For example:



    import arcpy

    fc = r'C:pathtoyourgeodatabase.gdbfeatureclass'

    with arcpy.da.UpdateCursor(fc, "some_field") as cursor:
    for row in cursor:
    if row[0] == None: # None appears as <Null> in attribute table float fields
    row[0] = 0
    cursor.updateRow(row)





    share|improve this answer



























      3














      I prefer to use an UpdateCursor to manipulate feature class attributes. However, make sure to use the modern Data Access da cursors. For example:



      import arcpy

      fc = r'C:pathtoyourgeodatabase.gdbfeatureclass'

      with arcpy.da.UpdateCursor(fc, "some_field") as cursor:
      for row in cursor:
      if row[0] == None: # None appears as <Null> in attribute table float fields
      row[0] = 0
      cursor.updateRow(row)





      share|improve this answer

























        3












        3








        3







        I prefer to use an UpdateCursor to manipulate feature class attributes. However, make sure to use the modern Data Access da cursors. For example:



        import arcpy

        fc = r'C:pathtoyourgeodatabase.gdbfeatureclass'

        with arcpy.da.UpdateCursor(fc, "some_field") as cursor:
        for row in cursor:
        if row[0] == None: # None appears as <Null> in attribute table float fields
        row[0] = 0
        cursor.updateRow(row)





        share|improve this answer













        I prefer to use an UpdateCursor to manipulate feature class attributes. However, make sure to use the modern Data Access da cursors. For example:



        import arcpy

        fc = r'C:pathtoyourgeodatabase.gdbfeatureclass'

        with arcpy.da.UpdateCursor(fc, "some_field") as cursor:
        for row in cursor:
        if row[0] == None: # None appears as <Null> in attribute table float fields
        row[0] = 0
        cursor.updateRow(row)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 4 at 3:56









        AaronAaron

        37.8k19107248




        37.8k19107248



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307543%2fconverting-none-to-zero-0-in-geodatabase-table-using-arcpy%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?