pandas.Series.values#
- property Series.values[source]#
Return Series as ndarray or ndarray-like depending on the dtype.
Warning
We recommend using
Series.arrayorSeries.to_numpy(), depending on whether you need a reference to the underlying data or a NumPy array. The return type of.valuesdepends on the dtype: it is anumpy.ndarrayfor some dtypes (for exampleint64orfloat64) and anExtensionArrayfor others (for examplecategory, nullableInt64, or string dtypes), which makes it harder to write code that works across dtypes..valuesalso converts timezone-aware datetimes to UTC and drops the timezone.Series.arrayalways returns the underlying array as anExtensionArray, andSeries.to_numpy()always returns anumpy.ndarrayand acceptsdtype,copy, andna_valuearguments to control the conversion.- Returns:
- numpy.ndarray or ndarray-like
See also
Series.arrayReference to the underlying data.
Series.to_numpyA NumPy array representing the underlying data.
Examples
For a Series backed by a NumPy dtype such as
int64,.valuesreturns anumpy.ndarray:>>> pd.Series([1, 2, 3]).values array([1, 2, 3])
For extension dtypes such as the default string dtype or
category,.valuesreturns anExtensionArrayinstead, whileSeries.to_numpy()always returns anumpy.ndarray:>>> pd.Series(list("aabc")).values <ArrowStringArray> ['a', 'a', 'b', 'c'] Length: 4, dtype: str >>> pd.Series(list("aabc")).to_numpy() array(['a', 'a', 'b', 'c'], dtype=object)
>>> pd.Series(list("aabc")).astype("category").values ['a', 'a', 'b', 'c'] Categories (3, str): ['a', 'b', 'c']
Timezone aware datetime data is converted to UTC and the timezone is dropped, while
Series.arraypreserves the timezone:>>> pd.Series(pd.date_range("20130101", periods=3, tz="US/Eastern")).values array(['2013-01-01T05:00:00.000000', '2013-01-02T05:00:00.000000', '2013-01-03T05:00:00.000000'], dtype='datetime64[us]') >>> pd.Series(pd.date_range("20130101", periods=3, tz="US/Eastern")).array <DatetimeArray> ['2013-01-01 00:00:00-05:00', '2013-01-02 00:00:00-05:00', '2013-01-03 00:00:00-05:00'] Length: 3, dtype: datetime64[us, US/Eastern]