What does the memory_usage() method tell you, and why should you pass deep=True?

Quick Overview

Asks what the pandas DataFrame memory_usage method reports and why the deep option changes the answer for object columns. Tests understanding of how pandas stores numeric and string data, how to measure a DataFrame's real footprint, and which dtype changes shrink it.

What does the memory_usage() method tell you, and why should you pass deep=True?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

In pandas, what does the `memory_usage()` method of a DataFrame tell you, and why should you pass `deep=True`? ```hint Follow the pointers Think about how an `object` column is stored in memory: what sits in the column's own buffer, and what lives elsewhere on the Python heap. ``` ### What a Strong Answer Covers - What the method returns, per column and for the index, and how to get a total - Why the default undercounts `object` columns and what `deep=True` adds - The cost of `deep=True` and any cases where even the deep number is off - How to use the result to shrink a DataFrame (downcasting, `category`, string dtypes) ### Follow-up Questions - A 1 million row column holds four distinct country codes as Python strings. Roughly how much memory does it take, and what would you convert it to? - Why does `df.info()` sometimes print the memory usage with a trailing `+`? - Your DataFrame reports 2 GB, but the process peaks at 8 GB during a merge. Where does the extra memory go? - When would converting a string column to `category` make memory use worse?

Overview: Asks what the pandas DataFrame memory_usage method reports and why the deep option changes the answer for object columns. Tests understanding of how pandas stores numeric and string data, how to measure a DataFrame's real footprint, and which dtype changes shrink it.

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

In pandas, what does the memory_usage() method of a DataFrame tell you, and why should you pass deep=True?

What a Strong Answer Covers Guidance

  • What the method returns, per column and for the index, and how to get a total
  • Why the default undercounts object columns and what deep=True adds
  • The cost of deep=True and any cases where even the deep number is off
  • How to use the result to shrink a DataFrame (downcasting, category , string dtypes)

Follow-up Questions Guidance

  • A 1 million row column holds four distinct country codes as Python strings. Roughly how much memory does it take, and what would you convert it to?
  • Why does df.info() sometimes print the memory usage with a trailing + ?
  • Your DataFrame reports 2 GB, but the process peaks at 8 GB during a merge. Where does the extra memory go?
  • When would converting a string column to category make memory use worse?