Skip to content

Instantly share code, notes, and snippets.

@d-wasserman
Last active April 19, 2021 20:50
Show Gist options
  • Save d-wasserman/5e3c1e7151ac8c6323bfb50ab525264f to your computer and use it in GitHub Desktop.
Save d-wasserman/5e3c1e7151ac8c6323bfb50ab525264f to your computer and use it in GitHub Desktop.
Returns pandas dataframe with all col names renamed to be valid ArcGIS table names.
import pandas as pd
import arcpy
def validate_df_names(dataframe,output_feature_class_workspace):
"""Returns pandas dataframe with all col names renamed to be valid arcgis table names."""
new_name_list=[]
old_names=dataframe.columns.names
for name in old_names:
new_name=arcpy.ValidateFieldName(name,output_feature_class_workspace)
new_name_list.append(new_name)
rename_dict={i:j for i,j in zip(old_names,new_name_list)}
dataframe.rename(index = str,columns=rename_dict)
return dataframe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment