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").

A

About 88 MB before and about 88 MB after: the strings are still stored once per row either way.

B

About 88 MB before and about 8 MB after, an 11x reduction.

C

About 64 MB before and about 8 MB after, an 8x reduction.

D

About 88 MB before and about 32 MB after, a 2.75x reduction.