Python Practice › Pandas Programs › Program 48

Column headers

EasyPandas Programs · 48 of 95

Write a pandas program to get a list of column headers.

Advertisement
Output
['name', 'sport']

Approach

  1. df.columns.tolist().

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Virat", "Messi", "Kobe"], "sport": ["cricket", "football", "basketball"]})print(df.columns.tolist())
Output
['name', 'sport']
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs