I have a csv file as such (I removed the commas and all):
ID Team Col3 Col4 Value
3 t1 c2 x1 0.124
6 t2 c11 x10 1.342
7 t3 c5 x2 0.654
4 t3 c5 x2 123.3
5 t2 c11 x10 75.2
9 t2 c11 x10 34.97
1 t1 c2 x1 0.23
I'm looking to group by Team, Col3, and Col4 and turn it into a dictionary whose values are ID and Value. So it looks like this
{
(t1, c2, x1): [[3, 0.124],[1, 0.23]],
(t2, c11, x10): [[6, 1.342], [5, 75.2], [9, 34.97]],
(t3, c5, x2): [[7, 0.654], [4, 123.3]]
}
My code right now is
df = pd.read_csv('file.csv')
gk = dict(df.groupby(['team', 'Col3', 'Col4']).apply(list))
This code returns the keys how I want them (in tuple form), but the values of each key are simply just the column names... like such
(t1, c2, x1): ['ID', 'team', 'Col3', 'Col4', 'Value']
How can I make it as such that the values of the dictionary are only the 'ID' and 'Value' columns?