Explain categorical data in Pandas.

Quick Overview

Asks you to explain the pandas category dtype: how values are stored, how ordered and unordered categories differ, and how to create and inspect them. Tests whether you know when the dtype saves memory and time and which pitfalls show up in grouping, assignment and concatenation.

Explain categorical data in Pandas.

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Explain categorical data in Pandas: what the `category` dtype is, how you work with it, and when it is worth using. ```hint Think about storage Consider how pandas could store a column of a million values when only a handful of distinct values ever appear in it. ``` ### What a Strong Answer Covers - What the `category` dtype stores and how each value maps to its stored representation. - The difference between unordered and ordered categories, and how it changes sorting and comparison. - How to create and inspect categorical columns. - When the dtype saves memory and time, and when it does not. - Pitfalls that come up in practice, such as unused categories and values outside the category list. ### Follow-up Questions - A `groupby` on a categorical column returns rows for categories that have no data. Why, and how do you control it? - What happens when you concatenate two categorical columns whose categories differ? - Would you convert a user ID column to `category`? Why or why not? - How would you feed a nominal categorical column into a linear model, and how does that change for a gradient-boosted tree library?

Overview: Asks you to explain the pandas category dtype: how values are stored, how ordered and unordered categories differ, and how to create and inspect them. Tests whether you know when the dtype saves memory and time and which pitfalls show up in grouping, assignment and concatenation.

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

Explain categorical data in Pandas: what the category dtype is, how you work with it, and when it is worth using.

What a Strong Answer Covers Guidance

  • What the category dtype stores and how each value maps to its stored representation.
  • The difference between unordered and ordered categories, and how it changes sorting and comparison.
  • How to create and inspect categorical columns.
  • When the dtype saves memory and time, and when it does not.
  • Pitfalls that come up in practice, such as unused categories and values outside the category list.

Follow-up Questions Guidance

  • A groupby on a categorical column returns rows for categories that have no data. Why, and how do you control it?
  • What happens when you concatenate two categorical columns whose categories differ?
  • Would you convert a user ID column to category ? Why or why not?
  • How would you feed a nominal categorical column into a linear model, and how does that change for a gradient-boosted tree library?