In my workflow there are multiple CSVs with four columns OID, value, count, unique_id. I am trying to figure how to generate incremental values under unique_id column. Using apply(), I can do something like df.apply(lambda x : x + 1) #where x = 0 and it will result in all values under unique_id as 1. However, I am confused on how to use apply() to generate incrementally values in each row for a specific column.
# Current Dataframe
OID Value Count unique_id
0 -1 1 5 0
1 -1 2 46 0
2 -1 3 32 0
3 -1 4 3 0
4 -1 5 17 0
# Trying to accomplish
OID Value Count unique_id
0 -1 1 5 0
1 -1 2 46 1
2 -1 3 32 2
3 -1 4 3 3
4 -1 5 17 4
Sample code (I understand that the syntax is incorrect, but it is approximately what I am trying to accomplish):
def numbers():
for index, row in RG_Res_df.iterrows():
return index
RG_Res_df = RG_Res_df['unique_id'].apply(numbers)
df['unique_id'] = np.arange(df.shape[0])