Answers for "convert a dataframe column to list of dictionary"

7

dataframe to list of dicts

df = pd.DataFrame({'Name': ['John', 'Sara','Peter','Cecilia'],
                   'Age': [38, 47,63,28],
                  'City':['Boston', 'Charlotte','London','Memphis']})

datadict = df.to_dict('records')
Posted by: Guest on October-22-2020
1

convert dict to dataframe

#Lazy way to convert json dict to df

pd.DataFrame.from_dict(data, orient='index').T
Posted by: Guest on April-29-2020

Code answers related to "convert a dataframe column to list of dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language