Converting none to zero (0) in geodatabase table using ArcPy?
I have an attribute table looks like this
How do I convert Nulls into 0?
I've tried to set this table non nullable type but got this:
while the official doc says this:
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?
I got a warning of
Your question has been identified as a possible duplicate of another question. If the answers there do not address your problem, please edit to explain in detail the parts of your question that are unique.
I'm very new to this form.So please forgive some beginner's fault.From what I saw it did bear some similarity to mine. But I do think the answers in mine is better.
If you have to join my question into his, please keep those answers.
arcpy field-calculator python-parser null
New contributor
add a comment |
I have an attribute table looks like this
How do I convert Nulls into 0?
I've tried to set this table non nullable type but got this:
while the official doc says this:
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?
I got a warning of
Your question has been identified as a possible duplicate of another question. If the answers there do not address your problem, please edit to explain in detail the parts of your question that are unique.
I'm very new to this form.So please forgive some beginner's fault.From what I saw it did bear some similarity to mine. But I do think the answers in mine is better.
If you have to join my question into his, please keep those answers.
arcpy field-calculator python-parser null
New contributor
also I've tried RValue.setValue(field,0) , also error 99999.
– Karl Tian
10 hours ago
so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.
– Karl Tian
10 hours ago
Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?
– Andy
10 hours ago
add a comment |
I have an attribute table looks like this
How do I convert Nulls into 0?
I've tried to set this table non nullable type but got this:
while the official doc says this:
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?
I got a warning of
Your question has been identified as a possible duplicate of another question. If the answers there do not address your problem, please edit to explain in detail the parts of your question that are unique.
I'm very new to this form.So please forgive some beginner's fault.From what I saw it did bear some similarity to mine. But I do think the answers in mine is better.
If you have to join my question into his, please keep those answers.
arcpy field-calculator python-parser null
New contributor
I have an attribute table looks like this
How do I convert Nulls into 0?
I've tried to set this table non nullable type but got this:
while the official doc says this:
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?
I got a warning of
Your question has been identified as a possible duplicate of another question. If the answers there do not address your problem, please edit to explain in detail the parts of your question that are unique.
I'm very new to this form.So please forgive some beginner's fault.From what I saw it did bear some similarity to mine. But I do think the answers in mine is better.
If you have to join my question into his, please keep those answers.
arcpy field-calculator python-parser null
arcpy field-calculator python-parser null
New contributor
New contributor
edited 6 hours ago
New contributor
asked 10 hours ago
Karl Tian
133
133
New contributor
New contributor
also I've tried RValue.setValue(field,0) , also error 99999.
– Karl Tian
10 hours ago
so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.
– Karl Tian
10 hours ago
Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?
– Andy
10 hours ago
add a comment |
also I've tried RValue.setValue(field,0) , also error 99999.
– Karl Tian
10 hours ago
so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.
– Karl Tian
10 hours ago
Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?
– Andy
10 hours ago
also I've tried RValue.setValue(field,0) , also error 99999.
– Karl Tian
10 hours ago
also I've tried RValue.setValue(field,0) , also error 99999.
– Karl Tian
10 hours ago
so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.
– Karl Tian
10 hours ago
so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.
– Karl Tian
10 hours ago
Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?
– Andy
10 hours ago
Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?
– Andy
10 hours ago
add a comment |
2 Answers
2
active
oldest
votes
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.
thank you, that just solve my problem
– Karl Tian
9 hours ago
You're welcome. :-)
– Son of a Beach
9 hours ago
that print there is to check the final result
– Karl Tian
8 hours ago
add a comment |
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)
add a comment |
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
});
}
});
Karl Tian is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
thank you, that just solve my problem
– Karl Tian
9 hours ago
You're welcome. :-)
– Son of a Beach
9 hours ago
that print there is to check the final result
– Karl Tian
8 hours ago
add a comment |
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.
thank you, that just solve my problem
– Karl Tian
9 hours ago
You're welcome. :-)
– Son of a Beach
9 hours ago
that print there is to check the final result
– Karl Tian
8 hours ago
add a comment |
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.
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.
edited 9 hours ago
answered 10 hours ago
Son of a Beach
1,403618
1,403618
thank you, that just solve my problem
– Karl Tian
9 hours ago
You're welcome. :-)
– Son of a Beach
9 hours ago
that print there is to check the final result
– Karl Tian
8 hours ago
add a comment |
thank you, that just solve my problem
– Karl Tian
9 hours ago
You're welcome. :-)
– Son of a Beach
9 hours ago
that print there is to check the final result
– Karl Tian
8 hours ago
thank you, that just solve my problem
– Karl Tian
9 hours ago
thank you, that just solve my problem
– Karl Tian
9 hours ago
You're welcome. :-)
– Son of a Beach
9 hours ago
You're welcome. :-)
– Son of a Beach
9 hours ago
that print there is to check the final result
– Karl Tian
8 hours ago
that print there is to check the final result
– Karl Tian
8 hours ago
add a comment |
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)
add a comment |
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)
add a comment |
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)
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)
answered 9 hours ago
Aaron♦
37.6k19107247
37.6k19107247
add a comment |
add a comment |
Karl Tian is a new contributor. Be nice, and check out our Code of Conduct.
Karl Tian is a new contributor. Be nice, and check out our Code of Conduct.
Karl Tian is a new contributor. Be nice, and check out our Code of Conduct.
Karl Tian is a new contributor. Be nice, and check out our Code of Conduct.
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
also I've tried RValue.setValue(field,0) , also error 99999.
– Karl Tian
10 hours ago
so many ways I've tried, either 99999 or apply to everything, other errors I've fixed.
– Karl Tian
10 hours ago
Possible duplicate of Unable to replace Null values using Python parser of ArcGIS 10.0 Field Calculator?
– Andy
10 hours ago