I have a dataframe which looks like this:
col_a | col_b |
---|---|
a | 1 |
a | 2 |
a | 3 |
b | 1 |
b | 2 |
b | 3 |
c | 1 |
c | 2 |
c | 3 |
I want to create a dictionary which looks like this (distinct/unique value for every key):
{a:1, b:2, c:3} or {a:3, b:2, c:1} or {a:2, b:1, c:3}, etc.
But with standard df.set_index(‘col_a’)[‘col_b’].to_dict() I get:
{a:3, b:3, c:3}.
Is there a way to create a dictionary with unique values for every key? Or is there a way to filter dataframe to do the same?