Examples
Dataframe to dictionary:
import numpy as np
import pandas as pd
df = pd.DataFrame({'c1': [1, 2],
'c2': [0.6, 0.85]},
index=['row1', 'row2'])
df
df.to_dict()
Specify the return orientation:
df.to_dict('series')
df.to_dict('split')
df.to_dict('records')
df.to_dict('index')
from collections import OrderedDict, defaultdict
df.to_dict(into=OrderedDict)
If you want a defaultdict, you need to initialize it:
dd = defaultdict(list)
df.to_dict('records', into=dd)