Converting a DataFrame to .values strips away all the labeled, pandas-specific structure and gives you the raw data as a NumPy array — useful when passing data into a library, like scikit-learn, that expects a plain array rather than a DataFrame. If the DataFrame's columns have mixed dtypes, some int, some float, some object, the resulting array is upcast to a single common dtype, typically object, which can silently lose the performance benefits of NumPy's native numeric types.
1Understanding df.values
Converting a DataFrame to .values strips away all the labeled, pandas-specific structure and gives you the raw data as a NumPy array — useful when passing data into a library, like scikit-learn, that expects a plain array rather than a DataFrame. If the DataFrame's columns have mixed dtypes, some int, some float, some object, the resulting array is upcast to a single common dtype, typically object, which can silently lose the performance benefits of NumPy's native numeric types.
Prefer df.to_numpy() over the older df.values for converting to a NumPy array in new code — to_numpy() is the modern, explicitly recommended method with clearer, more consistent behavior across pandas versions, though both currently do the same thing for most everyday use cases.
import pandas as pd
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
print(df.values)
print(type(df.values))2Practical Example
Here is a real-world application of df.values showing how it is used in production Pandas code.
import pandas as pd
df = pd.DataFrame({"a": [1, 2], "b": [1.5, 2.5]})
arr = df.values
print(arr.dtype)3Best Practices
Follow these guidelines when working with df.values:
1. Use df.to_numpy() instead of df.values in new code, since it's the currently recommended, more explicit method for the same conversion
2. Check the resulting array's dtype after converting a mixed-dtype DataFrame, since it commonly upcasts to a less specific type like object
3. Convert to a NumPy array only when a downstream tool specifically requires one — stay in DataFrame form otherwise to keep column labels and pandas' convenience methods available
Tip: Prefer df.to_numpy() over the older df.values for converting to a NumPy array in new code — to_numpy() is the modern, explicitly recommended method with clearer, more consistent behavior across pandas versions, though both currently do the same thing for most everyday use cases.
import pandas as pd
df = pd.DataFrame({"a": [1, 2], "b": [3, 4]})
print(df.values)
print(type(df.values))