What is the category data type, why use it, and how does it relate to one-hot encoding?

Quick Overview

Asks what the pandas category dtype is, why you would use it, and how it relates to one-hot encoding. Tests understanding of integer codes and stored categories, memory and speed trade-offs, ordered categories, and keeping encodings consistent for models.

What is the category data type, why use it, and how does it relate to one-hot encoding?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What is the `category` data type in pandas, why use it, and how does it relate to one-hot encoding? ```hint Look at the storage Compare what pandas keeps in memory for a column of repeated strings stored as `object` and stored as `category`, then think about what form a model needs. ``` ### What a Strong Answer Covers - How a categorical column is stored, and why that saves memory and time - When the dtype helps and when it does not, including cardinality and ordered categories - How it relates to integer codes and to one-hot encoding, and which models need which form - How a fixed category set keeps encodings consistent between training data and new data ### Follow-up Questions - When does converting a column to `category` fail to save memory? - How would you make sure the one-hot columns match between the training data and a batch scored a month later? - What happens when you concatenate two categorical columns with different category sets? - Which models can use a categorical column directly without one-hot encoding?

Overview: Asks what the pandas category dtype is, why you would use it, and how it relates to one-hot encoding. Tests understanding of integer codes and stored categories, memory and speed trade-offs, ordered categories, and keeping encodings consistent for models.

PracHub logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

What is the category data type in pandas, why use it, and how does it relate to one-hot encoding?

What a Strong Answer Covers Guidance

  • How a categorical column is stored, and why that saves memory and time
  • When the dtype helps and when it does not, including cardinality and ordered categories
  • How it relates to integer codes and to one-hot encoding, and which models need which form
  • How a fixed category set keeps encodings consistent between training data and new data

Follow-up Questions Guidance

  • When does converting a column to category fail to save memory?
  • How would you make sure the one-hot columns match between the training data and a batch scored a month later?
  • What happens when you concatenate two categorical columns with different category sets?
  • Which models can use a categorical column directly without one-hot encoding?