pandas.arrays.StringArray

class pandas.arrays.StringArray(values, copy=False)[source]

Extension array for string data.

New in version 1.0.0.

Warning

StringArray is considered experimental. The implementation and parts of the API may change without warning.

Parameters
valuesarray-like

The array of data.

Warning

Currently, this expects an object-dtype ndarray where the elements are Python strings or pandas.NA. This may change without warning in the future. Use pandas.array() with dtype="string" for a stable way of creating a StringArray from any sequence.

copybool, default False

Whether to copy the array of data.

See also

array

The recommended function for creating a StringArray.

Series.str

The string methods are available on Series backed by a StringArray.

Notes

StringArray returns a BooleanArray for comparison methods.

Examples

>>> pd.array(['This is', 'some text', None, 'data.'], dtype="string")
<StringArray>
['This is', 'some text', <NA>, 'data.']
Length: 4, dtype: string

Unlike object dtype arrays, StringArray doesn’t allow non-string values.

>>> pd.array(['1', 1], dtype="string")
Traceback (most recent call last):
...
ValueError: StringArray requires an object-dtype ndarray of strings.

For comparison methods, this returns a pandas.BooleanArray

>>> pd.array(["a", None, "c"], dtype="string") == "a"
<BooleanArray>
[True, <NA>, False]
Length: 3, dtype: boolean

Attributes

None

Methods

None