Tsallaka zuwa abun ciki
Justice Tech School

Categorical Data

The category dtype saves memory for repeated labels.

Example
s = pd.Series(["a", "b", "a", "c"], dtype="category")
print(s.cat.categories.tolist(), s.cat.codes.tolist())
print(s.dtype)

Result

['a', 'b', 'c'] [0, 1, 0, 2]
category

Exercise

Category type.

astype("")

Quiz Test

Why use category?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.