Skip to content

Instantly share code, notes, and snippets.

@pyRobShrk
Created August 6, 2018 21:19
Show Gist options
  • Save pyRobShrk/c791d22ba2823d013140997a3370e4dc to your computer and use it in GitHub Desktop.
Save pyRobShrk/c791d22ba2823d013140997a3370e4dc to your computer and use it in GitHub Desktop.
ArcPy function to copy the attribute table to clipboard for pasting into Excel
import pandas as pd
def GIStable2Clipboard(inTable, exportFields="all"):
desc = arcpy.Describe(inTable)
if exportFields =="all":
exportFields = [f.name for f in arcpy.ListFields(inTable) if not f.name == desc.shapeFieldName]
aliases = [f.aliasName for f in arcpy.ListFields(inTable) if not f.name == desc.shapeFieldName]
pd.DataFrame.from_records(arcpy.da.TableToNumPyArray(inTable,exportFields),
index=desc.OIDFieldName, columns=aliases).to_clipboard()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment