I've run into a problem and can't figure out how to solve this one.

I used the ModelBuilder and have a shapefile with loads of information. This information needs to be reduced. Therefore I want to select several rows (not all of them) out of several columns by attribute to delete them.

So for example, column X contains data with attributes a, b and c. I only want to delete c. Since I'm using the ModelBuilder, I need a tool from the toolbox which does that (preferably) in one step.

Any ideas?


Edit: The first method I posted wouldn't work. This one should though.

One straightforward way to do this would be to select everything you want to keep via Make Feature Layer with a where clause of X <> c. Then, use Copy Features to save the result.

  • I'll try that one. Thanks! I thought there might be a tool like 'Select' but working the opposite way. Thanks :) – Stophface Jun 20 '14 at 16:05
  • Just tried it. Its not working. Feature I saved is empty. Once I made the feature layer through selection and then delet the rows, the file must be empty... ? – Stophface Jun 20 '14 at 16:25
  • @Stophface, yes, I made a mistake. If you select everything you want to get rid of and then delete it, you'll be left with nothing. Try the 2nd option, where you select what you want to keep and then save to disk. – Paul Jun 20 '14 at 16:35
  • I've edited my post to reflect this. – Paul Jun 20 '14 at 16:43
  • Alright. I followed the steps you did before and it seemed not to work (the output data from the copy feature was empty) but it seemed - somehow - to have changed my original data... Everything I wanted to delet is deleted. Which is kind of good cause its gone but then its not good because it was my original dataset... – Stophface Jun 20 '14 at 17:08

To do this in one step I would use the Select (Analysis) tool which:

Extracts features from an input feature class or input feature layer, typically using a select or Structured Query Language (SQL) expression and stores them in an output feature class.

For your where_clause use:

"X" <> 'c'

I don't know if you're saying you want to delete the data in specific columns for specific rows or if you want to delete specific rows all together. If it is the latter, there is another answer already that uses Delete Rows that would likely work for you. If you are trying to just delete specific data from specific records though, the typical workflow for a situation like this, at least to me, would be something like the following:

Make Feature Layer (No SQL expression at this point)

Select Layer By Attribute (write the selection for the first column here, ex: ColumnX = 'c' or ColumnX IN ('a', 'd') )

Calculate Field (set expression type to Python or Python_9.3, set the expression to 0 if a numeric field or '' if a text field, and select the column in question ex: ColumnX as the Field Name)

Select Layer by Attribute (make sure Selection Type param is set to NEW_SELECTION and then write a selection for the next field you want to delete data from, ex: ColumnY = 3 or ColumnY IN (1, 4) )

Calculate Field (use same parameters as before but do for the relevant column, ex: ColumnY)

Repeat this select Layer by Attribute and Calculate Field operation until you have all data cleared from all fields as desired. At the end, depending on if your workflow needs to continue onto other steps or not, you may want to run Select Layer by Attribute a final time and set the Selection Type parameter to CLEAR_SELECTION

Yes, this is a lot longer than you were probably hoping for, but... Again, this is if your question was getting at trying to just delete all the occurrences of c from column x in your example. If you were trying to delete the entire row/record for any records that have c as the column x value, then try Paul or Erica's suggestions.

  • I have several columns with several attrbiutes i.e. column x with the attributes a,b,c and column y with the attributes e,r and t. I want to delet from column x the rows with the attribute a and from column y the rows with the attributes r and t. – Stophface Jun 20 '14 at 16:00
  • Alright. I will try that one. Why do I need to calculate field? – Stophface Jun 20 '14 at 17:59
  • Well, like I said in the answer, that is only to delete select data from select records. EX: You have a feature with ID=123, Name=ABC, ColumnX=C, etc.... Using the answer above, it would give you ID=123, Name=ABC, ColumnX= , etc... It would NOT delete the entire feature. It uses the calculate field to clear out the unwanted values. If you are wanting the delete the entire feature, I would go back and re-try and figure out what went wrong with Paul's answer. Try it on a copy of data though to test it until you get it working how you want. – John Jun 20 '14 at 18:14
  • What I do not understand is how i set the expression in calculating field... And what do you mean by "use the same parameters as before but for the relevant column"? Im sorry. I just started to learn ArcGis... I am pretty new and not sure what to do where... – Stophface Jun 20 '14 at 18:54
  • When you open the Calculate Field GP tool there should be a parameter called "Expression". You should be able to just type 0 or '' in the box for that parameter. And as far as "the same parameters", I just meant to do the same thing each time you need the calculate field tool throughout the process, except change the field name to the correct field name as needed each time and to change the expression, if needed, based on the field type. – John Jun 20 '14 at 18:59

In two steps:

MakeFeatureLayer_management with the where clause X = c.

-or if you already have a layer-

SelectLayerByAttribute_management with the where clause X = c.


DeleteFeatures_management using the layer.

Be careful that the selection is done properly on the layer otherwise it will delete all the features in that feature class. It is much safer to use Copy Features or Select to make a new layer as Paul and PolyGeo have said, so I would recommend doing it that way, however the question was Deleting features (rows) from shapefile (attribute table) using ModelBuilder? and that is how to do that.

  • I did it this way: With the "select Tool" I simply select everything I dont want. That creates a new layer. With the "erase Tool" I use my original Data and erase from that with the new created file through the "select command". Thank you all for your help guys! – Stophface Jun 21 '14 at 16:06

Use a select by attributes "Test" = 'a' or "Test" = 'b'

Then use the merge tool. This allows you to essentially select out to a new feature class and drop any extra fields too.

The delete tool is slow, the delete field is slow, and edit sessions can be a pain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.