Eight Million Country Codes
Pandas reports .nbytes for a str column as 8 bytes of pointer per element plus the UTF-8 bytes of each string. The user guide's own example: pd.Series(["foo", "bar"] * 1000).nbytes is 22000, and the same series as category is 2023.
A table has 8,000,000 rows. Its country column holds a 3-character ISO code drawn from 12 distinct codes, so the category codes fit in int8 (1 byte each).
Work out nbytes before and after astype("category").
Sign in to answer questions and track your progress
Sign In