I have a dataframe like this:
file:
| FIRST | LAST | ID |
---------------------------
0 "ABC" 12 35
1 "ABC" 14 35
2 "AB" 15 36
Now, what I want is:
file:
| FIRST | LAST | ID |
---------------------------
0 "ABC" [12,14] 35
2 "AB" 15 36
For this problem let's assume that if ID of two rows is equal then all the values except LAST is also equal.
Therefore, replace all the value except the values of last, which are added to a list.
I tried using solution given in this link: Pandas DataFrame - Combining one column's values with same index into list
I used this:
file = file.groupby('ID')
file = file['Last'].unique()
This is the output I got:
ID
35 [12, 14]
36 [15]
Name: Last, dtype: object
Probably, I am missing something in the groupby().
Thanks in advance :)
UPDATE:
My original Dataframe has more than 100 columns. if ID of two rows is equal then all the values except LAST is also equal.