I am trying to convert the following o/p of my SQL query (as a dataframe) to a dictionary of list:
Column A Column B
M N
M O
I want the result in following format:
{M:[N,O]}
Can someone help me in this?
>Solution :
You could try like this:
a_dict = df.groupby('Column A', as_index=True)['Column B'].apply(list).to_dict()
print(a_dict)
{'M': ['N', 'O']}