You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With object dtype, using ``.values`` on a Series will return the underlying NumPy array.
322
+
323
+
.. code-block:: python
324
+
325
+
>>> ser = pd.Series(["a", "b", np.nan], dtype="object")
326
+
>>>type(ser.values)
327
+
<class'numpy.ndarray'>
328
+
329
+
However with the new string dtype, the underlying ExtensionArray is returned instead.
330
+
331
+
.. code-block:: python
332
+
333
+
>>> ser = pd.Series(["a", "b", pd.NA], dtype="str")
334
+
>>> ser.values
335
+
<ArrowStringArray>
336
+
['a', 'b', nan]
337
+
Length: 3, dtype: str
338
+
339
+
If your code requires a NumPy array, you should use :meth:`Series.to_numpy`.
340
+
341
+
.. code-block:: python
342
+
343
+
>>> ser = pd.Series(["a", "b", pd.NA], dtype="str")
344
+
>>> ser.to_numpy()
345
+
['a''b' nan]
346
+
347
+
In general, you should always prefer :meth:`Series.to_numpy` to get a NumPy array or :meth:`Series.array` to get an ExtensionArray over using :meth:`Series.values`.
0 commit comments