Python Practice › Pandas Programs › Program 69
Select text columns
Write a pandas program to select the text columns.
Output
name city 0 Alex Pune 1 John Delhi
Approach
select_dtypes(include=...).
Solution
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John"], "city": ["Pune", "Delhi"], "age": [30, 27]})print(df.select_dtypes(exclude="number"))Output
name city 0 Alex Pune 1 John Delhi
Line by line
Line 3
Excluding numeric columns works on both old (object) and new (str) text types.
Learn the concept
New to this topic? Read the lesson, then come back.