I have a Dataframe or Numpy array with ascending group numbers, and I would like to assign a list of values (with equal length to the unique number of groups) repeated per group.
ID - Group
0 - 0
1 - 0
2 - 1
3 - 1
4 - 1
5 - 2
6 - 2
7 - 3
Values to assign:
[4, 2, 7, 8] # 4 maps to group 0, 2 maps to group 1 etc
Output:
ID - Group - Val
0 - 0 - 4
1 - 0 - 4
2 - 1 - 2
3 - 1 - 2
4 - 1 - 2
5 - 2 - 7
6 - 2 - 7
7 - 3 - 8
Appreciate any suggestions, preferably without looping if there are elegant ways/native functions to solve that (looking for both Numpy and Pandas solution).