Python Practice › Pandas Programs › Program 69

Select text columns

EasyPandas Programs · 69 of 95

Write a pandas program to select the text columns.

Advertisement
Output
   name   city
0  Alex   Pune
1  John  Delhi

Approach

  1. select_dtypes(include=...).

Solution

Python
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.

Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs