I have a dataframe as follows:
A B C
1 6 1
2 5 7
3 4 9
4 2 2
I want a dictionary like this:
{A: [1,2,3,4], B:[6,5,4,2], C:[1,7,9,2]}
I have tried using the normal df.to_dict() and it is no where close. If I use the transposed dataframe, hence df.T.to_dict() it gets close, but I have something like this:
{0: {A: 1, B: 6, C:1} , ... , 4:{A: 4, B: 2, C: 2 } }
The questions in stack overflow are limited to the dictionary having one value per key, not an array.
It would be very valuable for me to use to_dict() and avoid any for loop, since the database I am using is quite big and I want the computational complexity to be as low as possible.
df.to_dict(orient='list')ordf.to_dict('l')orient=keyword into_dict