python
Convert a dictionary to pandas DataFrame in python
To convert a python dictionary to a pandas DataFrame, the from_dict() of DataFrame can be used.
import pandas as pd
my_dict = [{'Name': 'John', 'Score': 20}, {'Name': 'Mark', 'Score': 50}, {'Name': 'Rick', 'Score': 70}]
df = pd.DataFrame.from_dict(my_dict)
print(df)
# +----+--------+---------+
# | | Name | Score |
# +-------------+---------+
# | 0 | John | 20 |
# | 1 | Mark | 50 |
# | 2 | Rick | 70 |
# +----+--------+---------+
In the code snippet, we have created a list of dictionary my_dict which has two keys in each dictionary Name and Score. We are using the from_dict() method which is consuming this dictionary and making a DataFrame from it.
Was this helpful?
Similar Posts
- Convert pandas DataFrame to python collection - dictionary
- Convert a Python Dictionary to Pandas DataFrame
- Pandas dataframe to dictionary conversion python
- Convert pandas DataFrame to List of dictionaries python
- Pandas - How to check whether a pandas DataFrame is empty
- Pandas - Delete,Remove,Drop, column from pandas DataFrame
- [Python] Using comprehension expression to convert list of dictionaries to nested dictionary