Created
July 16, 2014 05:21
-
-
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
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
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