0

I have a dataframe that looks like this:

   a  b
0  2  4
1  6  7
2  2  5

What I want is a dictionary (or some similar type of data structure) that keeps track of corresponding values of 'b' for values of 'a'. The output for this dataframe would look like this:

'2'  :  [4, 5]
'6'  :  [7]

I know I could do this with a loop but I'm wondering if there are any faster and more concise built in functions I could use instead. I'm thinking there may be a way to use groupby but I only want the values in 'b', not the whole column.

UBears
  • 371
  • 1
  • 4
  • 18

0 Answers0