Python Practice › Pandas Programs › Program 62

List of lists to DataFrame

EasyPandas Programs · 62 of 95

Write a pandas program to convert a list of lists into a DataFrame.

Advertisement
Input
[["Virat", "cricket"], ["Messi", "football"]]
Output
    name     sport
0  Virat   cricket
1  Messi  football

Approach

  1. Pass columns=.

Solution

Python
import pandas as pdprint(pd.DataFrame([["Virat", "cricket"], ["Messi", "football"]], columns=["name", "sport"]))
Output
    name     sport
0  Virat   cricket
1  Messi  football
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs