I have a dataframe :
df.head() :
col_a col_a Month 1 Month 2 Month 3 Month 4 Month 5 Month 6
10 2
20 6
44 3
55 1
86 4
67 5
What I want do : I want values of col_a to be assigned based on col_b in a specific month, for example, the first value of column_a ie 10 should be assigned to Month 2 based on 2 that is coming from col_b Similarly, for col_a=67 should be assigned to Month 5
output:
col_a col_b Month 1 Month 2 Month 3 Month 4 Month 5 Month 6
10 2 10
20 6 20
44 3 44
55 1 55
86 4 86
67 5 67
I can do this by iterating over each row and extracting the value from col_b and using regex to match the appropriate month, and then assigning the value. Since I have a large number of rows 3000+ this is going to take time. Can somebody help with a better approach?
PS:- The dtype is str not int.