I'm trying to create a dictionary from a pandas data frame with key from a column and values from rest of columns. But the problem is I will have same keys in multiple rows and I've read through many other similar SO posts but couldn't find the answer. This is what I have:
df1:
pid feature_id feature_value
78 20 1.0
78 1130 3.0
...
91 1148 1.0
92 1153 4.0
92 1154 1.0
...
115 1162 1.0
115 1175 5.0
......
This is what I tried:
df2 = df1.set_index('pid').agg(tuple, 1).to_dict()
But problem is this seems to not take into account the same keys from multiple rows.
What I want is something like this:
{78: [(20, 1.0), (1130, 3.0)]..., 115: [(1162, 1.0), (1175, 5.0)], ...}
Please advise.