w3resource

Pandas Series: array() function

An ExtensionArray in Pandas

The ExtensionArray of the data backing Pandas Series or Index.

Syntax:

Series.array
Pandas Series array() function

Returns: ExtensionArray - An ExtensionArray of the values stored within.
For extension types, this is the actual array.
For NumPy native types, this is a thin (no copy) wrapper around numpy.ndarray.

Following table lays out the different array types for each extension dtype within pandas.

dtype array type
category

Categorical

period PeriodArray
interval IntervalArray
IntegerNA IntegerArray
datetime64[ns, tz] DatetimeArray

For any 3rd-party extension types, the array type will be an ExtensionArray.
For all remaining dtypes .array will be a arrays.NumpyExtensionArray wrapping the actual ndarray stored within. If you absolutely need a NumPy array (possibly with copying / coercing data), then use Series.to_numpy() instead.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts