I have a pandas dataframe and i wanted to convert into dictionary.
email,account_no,cust_id
xyz,123,456
abc,789,654
nbc,345,907
From the df i wanted the email to be as key and other two column as value. Needed output like
{xyz:[123,456],
abc:[789,654],
nbc:[345,907]}
Can anybody let me know how this can be achieved ?.
Try:
df.set_index('email').T.to_dict('list')
# output
{'xyz': [123, 456], 'abc': [789, 654], 'nbc': [345, 907]}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.