Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

create dictionary without removing duplicates from dataframe

df.groupby(level=0).apply(lambda x: x.to_dict('r')).to_dict()
# {'bob': [{'age': 20, 'name': 'bob'}, {'age': 30, 'name': 'bob'}],
#  'jim': [{'age': 25, 'name': 'jim'}]}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #create #dictionary #removing #duplicates #dataframe
ADD COMMENT
Topic
Name
7+8 =