Conversion of list of dictionary and dataframe in Python

In Python there is a dataframe package: pandas. The dataframe package simplifies a lot of things and it is comparable to a dataframe in R. Sometime you need convert a list of dictionary to a dataframe and vice versa.

To use dataframe you need import pandas.

To convert a list of dictionary to a dataframe, use the following:

pandas.DataFrame(a_list_dict)

To convert a dataframe to a list of dictionary, use the following:

list(df.T.to_dict().values())

Share
This entry was posted in Python and tagged , , , . Bookmark the permalink.

Leave a Reply