Robl09
Robl09

Reputation: 41

Creating a dictionary with multiple values per key from specific columns in a dataframe

email_ad                 Name       Manager_Name   Manager_Band_level 
[email protected]. Tom Banks  Boss1          30
[email protected].  Bill Bob   Boss2          40

How do I create a dictionary with email_ad as the key and each of the other columns in my data frame as values. I tried this

mydict={df['email_ad']:[df['Name'],df['Manager Name'], df['Manager_Band_level']]}

This did not work. I have been stuck forever on this. Any help would be amazing!

Upvotes: 0

Views: 41

Answers (1)

Space Impact
Space Impact

Reputation: 13255

Use zip with dict as:

mydict = dict(zip(df['email_ad'], df.iloc[:, 1:].to_numpy().tolist()))

mydict
{'[email protected].': ['Tom Banks', 'Boss1', 30],
 '[email protected].': ['Bill Bob', 'Boss2', 40]}

Upvotes: 1

Related Questions