Categorical Data in Python

From the Pandas cheat sheet ยท Text and Categories ยท verified Aug 2026

Categorical Data

Represent repeated finite labels efficiently.

python
df["size"] = df["size"].astype("category")
๐Ÿ’ก Categories reduce memory for repeated labels
๐Ÿ“Œ Ordered categories support meaningful sorting
โš ๏ธ Add a category before assigning a new label
๐Ÿ” cat accessor manages category metadata
categorydtypememory

Continue with Pandas

Save the full cheat sheet or work through every related task.

More Python tasks

Back to the full Pandas cheat sheet