Python Practice › Pandas Programs › Program 29

Dictionary to DataFrame

EasyPandas Programs · 29 of 95

Write a pandas program to convert a dictionary into a DataFrame.

Advertisement
Output
    name  age
0   Alex   30
1   John   27
2  Peter   29

Approach

  1. Each key becomes a column.

Solution

Python
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
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs