Sometimes, we want to construct a Python Pandas DataFrame from items in nested dictionary.
In this article, we’ll look at how to construct a Python Pandas DataFrame from items in nested dictionary.
How to construct a Python Pandas DataFrame from items in nested dictionary?
To construct a Python Pandas DataFrame from items in nested dictionary, we can use dictionary comprehension to get the values we want before creating the data frame.
For instance, we write
pd.concat({k: pd.DataFrame(v).T for k, v in user_dict.items()}, axis=0)
to call pd.concat
with a fictionary that we create from creating the DataFrame
with value v
that we get from the key-value pairs returned by items
.
Conclusion
To construct a Python Pandas DataFrame from items in nested dictionary, we can use dictionary comprehension to get the values we want before creating the data frame.