Python Practice › Pandas Programs › Program 62
List of lists to DataFrame
Write a pandas program to convert a list of lists into a DataFrame.
Input
[["Virat", "cricket"], ["Messi", "football"]]
Output
name sport 0 Virat cricket 1 Messi football
Approach
- Pass
columns=.
Solution
import pandas as pdprint(pd.DataFrame([["Virat", "cricket"], ["Messi", "football"]], columns=["name", "sport"]))Output
name sport 0 Virat cricket 1 Messi football
Learn the concept
New to this topic? Read the lesson, then come back.