I have this pandas dataframe :
df
ID Value
0 1 0.33
1 1 0.91
2 1 0.28
3 2 0.36
4 2 0.50
5 3 0.47
6 3 0.98
7 3 0.34
8 3 0.37
I want to group by ID and create 2 new columns :
- "values_in" which is a list of value column for the ID
- "values_out" which is a list of value column for the other IDs
The output will be like this :
ID values_in values_out
0 1 [0.33, 0.91, 0.28] [0.36, 0.5, 0.47, 0.98, 0.34, 0.37]
1 2 [0.36, 0.5] [0.33, 0.91, 0.28, 0.47, 0.98, 0.34, 0.37]
2 3 [0.47, 0.98, 0.34, 0.37] [0.33, 0.91, 0.28, 0.36, 0.5]
How can I do that knowing that if I use classic groupby I will automatically exclude the values_out?
FYI : I do not care about the order in the lists.