I have a dataframe with 2 columns name
and age
I want to make a list of dictionaries containing their value of name
and age
which is like this
list = [{'a':'14'}, {'b':'21'}, {'c':'12'}]
I've tried using list = [{i:j} for i,j in df['name'],df['age']]
but apparently it cannot loop from 2 for in
. How can I loop the list of dictionaries?
EDIT
I have completed it with list = [{i:j} for i,j in zip(df['name'],df['age'])]
Thank you for the answers!