Answers for "convert dataframe rows to list of dicts"

8

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
0

list of dict to dataframe

Supposing d is your list of dicts, simply:
import pandas as pd 

df = pd.DataFrame(d)
Posted by: Guest on November-21-2021

Code answers related to "convert dataframe rows to list of dicts"

Browse Popular Code Answers by Language