df.to_dict: Turn a DataFrame into a Dictionary

df.to_dict: Turn a DataFrame into a Dictionary

To turn a DataFrame into a Python dictionary, use df.to_dict(). This will return a dictionary whose keys are columns.

If you prefer to get a list of dictionaries whose elements are rows, use df.to_dict(orient='records') instead.

Link to my previous tips on pandas.

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran