What does converting a low-cardinality object column with astype('category') change?
Correct answer
B. It stores integer codes plus a dictionary of categories, cutting memory and enabling ordered comparisons
14 views
B. It stores integer codes plus a dictionary of categories, cutting memory and enabling ordered comparisons
14 views
Categorical dtype replaces repeated strings with small integer codes pointing to a shared category index, which can cut memory by an order of magnitude when few distinct values repeat often. It also records category order, making ordered comparisons and correct sorting possible. groupby on a categorical includes unobserved categories unless observed=True is passed.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.