Skip to content

Instantly share code, notes, and snippets.

@maptastik
Created November 26, 2019 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maptastik/ee5605ce98417d6db4392523e8f04e99 to your computer and use it in GitHub Desktop.
Save maptastik/ee5605ce98417d6db4392523e8f04e99 to your computer and use it in GitHub Desktop.
A quick method for writing out some rows and a subset of columns from a feature class to a CSV. This is particularly well-suited for when you're working in ArcGIS Desktop or Pro and need to quickly export some rows and a subset of columns from a vect
import arcpy
import csv
with open('output.csv', 'w', newline = '') as csvfile:
writer = csv.writer(csvfile) # Create writer object
writer.writerow(['Column 1', 'Column 2', 'Column 3', 'Column 4']) # Define the header row
with arcpy.da.SearchCursor('input_layer', ['Field1', 'Field2', 'Field3', 'Field4']) as cursor: # Define cursor object
for row in cursor:
writer.writerow([row[0], row[1], row[2], row[3]]) # Write values from each item in cursor to csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment