I'd like to make a dictionary from two columns filtered from DataFrame. Content of the first column should be dictionary's key and from the second should be values of given key.
Example:
keys | vals |
---|---|
203 | 4 |
203 | 3 |
203 | 6 |
412 | 33 |
412 | 123 |
Such a dataframe I want transform to:
final_dict = {
"203": [4, 3, 6],
"412": [33, 123]
}
Is there any fast method to avoid loops? Are they necessary here?