Created
November 26, 2019 16:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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