to_dict(orient='records') orient=records .
In [2]: df[['x', 'y']].to_dict(orient='records')
Out[2]:
[{'x': 0.5, 'y': 0.1}, {'x': 0.6, 'y': 0.2}]
In [8]: df.shape
Out[8]: (10000, 4)
In [9]: %timeit df[['x', 'y']].to_dict(orient='records')
10 loops, best of 3: 68.4 ms per loop
In [10]: %timeit df[['x','y']].to_dict('index').values()
1 loop, best of 3: 570 ms per loop
In [11]: %timeit list(row.to_dict() for key, row in df[['x', 'y']].iterrows())
1 loop, best of 3: 575 ms per loop
source
share