What is the difference between .values and .to_numpy() in pandas?

Quick Overview

Asks how the pandas .values attribute and the .to_numpy() method differ when pulling the data out of a Series or DataFrame. Tests knowledge of extension dtypes such as nullable integers and categoricals, explicit dtype and missing-value control, and copy behavior.

What is the difference between .values and .to_numpy() in pandas?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

In pandas, what is the difference between `.values` and `.to_numpy()` on a Series or DataFrame? ```hint Look past plain dtypes For a float column the two look identical. Try a column whose dtype pandas defines itself, such as a nullable integer or a category, and check what type each one returns. ``` ### What a Strong Answer Covers - Says what both return for ordinary NumPy-backed columns. - Explains how they differ for pandas extension dtypes such as nullable integers, categoricals and time-zone-aware datetimes. - Names the parameters that give explicit control over the conversion. - Gives a recommendation for new code, including what to use when you want the pandas-native array. ### Follow-up Questions - If you modify the array returned by `.to_numpy()`, can the original DataFrame change, and how do you make sure it cannot? - What does `df.to_numpy()` return for a DataFrame with one integer column and one string column, and why can that hurt performance? - When would you use `.array` in place of `.to_numpy()`? - How should you convert a nullable `Int64` column with missing values before passing it to scikit-learn?

Overview: Asks how the pandas .values attribute and the .to_numpy() method differ when pulling the data out of a Series or DataFrame. Tests knowledge of extension dtypes such as nullable integers and categoricals, explicit dtype and missing-value control, and copy behavior.

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

In pandas, what is the difference between .values and .to_numpy() on a Series or DataFrame?

What a Strong Answer Covers Guidance

  • Says what both return for ordinary NumPy-backed columns.
  • Explains how they differ for pandas extension dtypes such as nullable integers, categoricals and time-zone-aware datetimes.
  • Names the parameters that give explicit control over the conversion.
  • Gives a recommendation for new code, including what to use when you want the pandas-native array.

Follow-up Questions Guidance

  • If you modify the array returned by .to_numpy() , can the original DataFrame change, and how do you make sure it cannot?
  • What does df.to_numpy() return for a DataFrame with one integer column and one string column, and why can that hurt performance?
  • When would you use .array in place of .to_numpy() ?
  • How should you convert a nullable Int64 column with missing values before passing it to scikit-learn?