Python Practice › Pandas Programs › Program 32
Select columns
Write a pandas program to print selected columns.
Input
name and age from a table with Sr.no, name, age
Output
name age 0 Alex 30 1 John 27 2 Peter 29
Approach
df[["name", "age"]].
Solution
import pandas as pddf = pd.DataFrame({"sr_no": [1, 2, 3], "name": ["Alex", "John", "Peter"], "age": [30, 27, 29]})print(df[["name", "age"]])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.