- API reference
- Series
- pandas.Series.array
pandas.Series.array#
- propertySeries.array[source]#
The ExtensionArray of the data backing this Series or Index.
- Returns:
- ExtensionArray
An ExtensionArray of the values stored within. For extensiontypes, this is the actual array. For NumPy native types, thisis a thin (no copy) wrapper around
numpy.ndarray
..array
differs from.values
, which may require convertingthe data to a different form.
See also
Index.to_numpy
Similar method that always returns a NumPy array.
Series.to_numpy
Similar method that always returns a NumPy array.
Notes
This table lays out the different array types for each extensiondtype within pandas.
dtype
array type
category
Categorical
period
PeriodArray
interval
IntervalArray
IntegerNA
IntegerArray
string
StringArray
boolean
BooleanArray
datetime64[ns, tz]
DatetimeArray
For any 3rd-party extension types, the array type will be anExtensionArray.
For all remaining dtypes
.array
will be aarrays.NumpyExtensionArray
wrapping the actual ndarraystored within. If you absolutely need a NumPy array (possibly withcopying / coercing data), then useSeries.to_numpy()
instead.Examples
For regular NumPy types like int, and float, a NumpyExtensionArrayis returned.
>>>pd.Series([1,2,3]).array<NumpyExtensionArray>[1, 2, 3]Length: 3, dtype: int64
For extension types, like Categorical, the actual ExtensionArrayis returned
>>>ser=pd.Series(pd.Categorical(['a','b','a']))>>>ser.array['a', 'b', 'a']Categories (2, object): ['a', 'b']