Python Practice › Pandas Programs › Program 29
Dictionary to DataFrame
Write a pandas program to convert a dictionary into a DataFrame.
Output
name age 0 Alex 30 1 John 27 2 Peter 29
Approach
- Each key becomes a column.
Solution
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter"], "age": [30, 27, 29]})print(df)Output
name age 0 Alex 30 1 John 27 2 Peter 29
Learn the concept
New to this topic? Read the lesson, then come back.