Select text columns
Write a pandas program to select the text columns.
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"))name city 0 Alex Pune 1 John Delhi
Line by line
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.