Skip to content

Instantly share code, notes, and snippets.

@morehavoc
Created July 16, 2014 05:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morehavoc/e9e106ebb2139f92fab1 to your computer and use it in GitHub Desktop.
Save morehavoc/e9e106ebb2139f92fab1 to your computer and use it in GitHub Desktop.
A quick script to create a unique ID based on the value of a different column. For example, the column value might have 3 rows with value A and 2 rows with B, the script would calc a new column that would make A_001, A_002, A_003, B_001, B_002
global id_value_dict
id_value_dict = dict()
def calc_new_id(base_id_value):
global id_value_dict
if base_id_value in id_value_dict:
id_value_dict[base_id_value] += 1
else:
id_value_dict[base_id_value] = 1
return str(base_id_value) + "_" + str(id_value_dict[base_id_value]).zfill(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment