mercredi 27 juillet 2016

Convert Pandas DataFrame to dictionary

I have a DataFrame with four columns. I want to convert this DataFrame to a python dictionary. I want the elements of first column be keys and the elements of other columns in same row be values.

Dataframe:

    ID   A   B   C
0   p    1   3   2
1   q    4   3   2
2   r    4   0   9  

Output should be like this:

Dictionary:

{'p': [1,3,2],'q': [4,3,2],'r': [4,0,9]}

Aucun commentaire:

Enregistrer un commentaire