Checking field is empty and then adding new row with zeros? Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?ArcPy Insert Cursor not inserting all rows?How to check for empty values in fields of a featureclass?Getting first and second row with ArcPy searchcursor?ArcPy Calculate Null Values to Zero in Multiple FieldsUsing SearchCursor - TypeError: Not a Spatial ReferenceWriting ArcPy UpdateCursor based on row test?Search Cursor Return Field Name If All Rows Contain a ValueUsing ArcPy to ListFields inside SearchCursor?Adding row with default values to new created table with ArcPy?Switching from Nested Search Cursors to Dictionaries
Why is it faster to reheat something than it is to cook it?
Sum letters are not two different
Why is Nikon 1.4g better when Nikon 1.8g is sharper?
What is a fractional matching?
Can anything be seen from the center of the Boötes void? How dark would it be?
How much damage would a cupful of neutron star matter do to the Earth?
Performance gap between vector<bool> and array
How would a mousetrap for use in space work?
Crossing US/Canada Border for less than 24 hours
Why do we need to use the builder design pattern when we can do the same thing with setters?
What do you call the main part of a joke?
What does it mean that physics no longer uses mechanical models to describe phenomena?
Did Deadpool rescue all of the X-Force?
How to tell that you are a giant?
Is there a kind of relay that only consumes power when switching?
What is the difference between globalisation and imperialism?
Is it fair for a professor to grade us on the possession of past papers?
How to write this math term? with cases it isn't working
Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?
A term for a woman complaining about things/begging in a cute/childish way
How to play a character with a disability or mental disorder without being offensive?
Why weren't discrete x86 CPUs ever used in game hardware?
Take 2! Is this homebrew Lady of Pain warlock patron balanced?
Significance of Cersei's obsession with elephants?
Checking field is empty and then adding new row with zeros?
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?ArcPy Insert Cursor not inserting all rows?How to check for empty values in fields of a featureclass?Getting first and second row with ArcPy searchcursor?ArcPy Calculate Null Values to Zero in Multiple FieldsUsing SearchCursor - TypeError: Not a Spatial ReferenceWriting ArcPy UpdateCursor based on row test?Search Cursor Return Field Name If All Rows Contain a ValueUsing ArcPy to ListFields inside SearchCursor?Adding row with default values to new created table with ArcPy?Switching from Nested Search Cursors to Dictionaries
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I created a table with three fields but there are no values in these fields. Here is the screenshot of these fields.
I want to add a new row with zeros for all these three fields. Here is my code.
with arcpy.da.UpdateCursor(selectionname,("OBJECTID","FREQUENCY","SUM_Shape_Area")) as cursor:
for row in cursor:
if row[0] == None:
row[0] = 0
cursor.updateRow(row)
else:
print selectionname + " is not empty"
Selectionname is my table, a parameter defined prior to this part of my code. First, I need to check if these three fields are empty, then adding a new row with zeros if they are empty. After several tries, I still could not add a new row to the table.
arcpy arcgis-pro cursor
add a comment |
I created a table with three fields but there are no values in these fields. Here is the screenshot of these fields.
I want to add a new row with zeros for all these three fields. Here is my code.
with arcpy.da.UpdateCursor(selectionname,("OBJECTID","FREQUENCY","SUM_Shape_Area")) as cursor:
for row in cursor:
if row[0] == None:
row[0] = 0
cursor.updateRow(row)
else:
print selectionname + " is not empty"
Selectionname is my table, a parameter defined prior to this part of my code. First, I need to check if these three fields are empty, then adding a new row with zeros if they are empty. After several tries, I still could not add a new row to the table.
arcpy arcgis-pro cursor
4
To add a new row you need to be using an InsertCursor.
– PolyGeo♦
Apr 11 at 2:46
add a comment |
I created a table with three fields but there are no values in these fields. Here is the screenshot of these fields.
I want to add a new row with zeros for all these three fields. Here is my code.
with arcpy.da.UpdateCursor(selectionname,("OBJECTID","FREQUENCY","SUM_Shape_Area")) as cursor:
for row in cursor:
if row[0] == None:
row[0] = 0
cursor.updateRow(row)
else:
print selectionname + " is not empty"
Selectionname is my table, a parameter defined prior to this part of my code. First, I need to check if these three fields are empty, then adding a new row with zeros if they are empty. After several tries, I still could not add a new row to the table.
arcpy arcgis-pro cursor
I created a table with three fields but there are no values in these fields. Here is the screenshot of these fields.
I want to add a new row with zeros for all these three fields. Here is my code.
with arcpy.da.UpdateCursor(selectionname,("OBJECTID","FREQUENCY","SUM_Shape_Area")) as cursor:
for row in cursor:
if row[0] == None:
row[0] = 0
cursor.updateRow(row)
else:
print selectionname + " is not empty"
Selectionname is my table, a parameter defined prior to this part of my code. First, I need to check if these three fields are empty, then adding a new row with zeros if they are empty. After several tries, I still could not add a new row to the table.
arcpy arcgis-pro cursor
arcpy arcgis-pro cursor
edited Apr 11 at 3:39
Vince
14.8k32850
14.8k32850
asked Apr 11 at 2:41
ZhenyuZhenyu
234
234
4
To add a new row you need to be using an InsertCursor.
– PolyGeo♦
Apr 11 at 2:46
add a comment |
4
To add a new row you need to be using an InsertCursor.
– PolyGeo♦
Apr 11 at 2:46
4
4
To add a new row you need to be using an InsertCursor.
– PolyGeo♦
Apr 11 at 2:46
To add a new row you need to be using an InsertCursor.
– PolyGeo♦
Apr 11 at 2:46
add a comment |
1 Answer
1
active
oldest
votes
Use GetCount to check if table is empty and da.InsertCursor to insert a row. I dont think you should try to set objectid, let it be set automatically. If you want your own ID then add another field for it.
import arcpy
table = 'C:data.gdbtable123' #Change
fields = ['freq','sum'] #Change
if int(arcpy.GetCount_management(table).getOutput(0)) == 0:
icur = arcpy.da.InsertCursor(table,fields)
icur.insertRow([0,0])
del icur
1
this is what I want and really appreciate your help! @BERA
– Zhenyu
Apr 11 at 19:43
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
);
);
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%2f318440%2fchecking-field-is-empty-and-then-adding-new-row-with-zeros%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use GetCount to check if table is empty and da.InsertCursor to insert a row. I dont think you should try to set objectid, let it be set automatically. If you want your own ID then add another field for it.
import arcpy
table = 'C:data.gdbtable123' #Change
fields = ['freq','sum'] #Change
if int(arcpy.GetCount_management(table).getOutput(0)) == 0:
icur = arcpy.da.InsertCursor(table,fields)
icur.insertRow([0,0])
del icur
1
this is what I want and really appreciate your help! @BERA
– Zhenyu
Apr 11 at 19:43
add a comment |
Use GetCount to check if table is empty and da.InsertCursor to insert a row. I dont think you should try to set objectid, let it be set automatically. If you want your own ID then add another field for it.
import arcpy
table = 'C:data.gdbtable123' #Change
fields = ['freq','sum'] #Change
if int(arcpy.GetCount_management(table).getOutput(0)) == 0:
icur = arcpy.da.InsertCursor(table,fields)
icur.insertRow([0,0])
del icur
1
this is what I want and really appreciate your help! @BERA
– Zhenyu
Apr 11 at 19:43
add a comment |
Use GetCount to check if table is empty and da.InsertCursor to insert a row. I dont think you should try to set objectid, let it be set automatically. If you want your own ID then add another field for it.
import arcpy
table = 'C:data.gdbtable123' #Change
fields = ['freq','sum'] #Change
if int(arcpy.GetCount_management(table).getOutput(0)) == 0:
icur = arcpy.da.InsertCursor(table,fields)
icur.insertRow([0,0])
del icur
Use GetCount to check if table is empty and da.InsertCursor to insert a row. I dont think you should try to set objectid, let it be set automatically. If you want your own ID then add another field for it.
import arcpy
table = 'C:data.gdbtable123' #Change
fields = ['freq','sum'] #Change
if int(arcpy.GetCount_management(table).getOutput(0)) == 0:
icur = arcpy.da.InsertCursor(table,fields)
icur.insertRow([0,0])
del icur
edited Apr 12 at 5:23
answered Apr 11 at 5:42
BERABERA
17.2k62044
17.2k62044
1
this is what I want and really appreciate your help! @BERA
– Zhenyu
Apr 11 at 19:43
add a comment |
1
this is what I want and really appreciate your help! @BERA
– Zhenyu
Apr 11 at 19:43
1
1
this is what I want and really appreciate your help! @BERA
– Zhenyu
Apr 11 at 19:43
this is what I want and really appreciate your help! @BERA
– Zhenyu
Apr 11 at 19:43
add a comment |
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.
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%2f318440%2fchecking-field-is-empty-and-then-adding-new-row-with-zeros%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
4
To add a new row you need to be using an InsertCursor.
– PolyGeo♦
Apr 11 at 2:46