1. Home
  2. Data Science
  3. Pandas
  4. What does converting a low-cardinality object column with…

Added 30 Nov -0001

What does converting a low-cardinality object column with astype('category') change?

  1. It converts every string to an interned string object, for faster hashing and lower memory use
  2. It stores integer codes plus a dictionary of categories, cutting memory and enabling ordered comparisons Correct answer
  3. It drops duplicate values from the column, keeping only the first occurrence of every distinct string value
  4. It permanently sorts the DataFrame by that column and rebuilds the row index in sorted order

Correct answer

B. It stores integer codes plus a dictionary of categories, cutting memory and enabling ordered comparisons

14 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs