Skip to main content
`Ctrl`+`K`

# pandas.arrays.StringArray

class pandas.arrays.StringArray(values, *, dtype=None, copy=False)

  Extension array for string data.

  Warning

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

  Parameters:
    values array-like

      The array of data.

      Warning

      Currently, this expects an object-dtype ndarray where the elements are Python strings or nan-likes (`None`, `np.nan`, `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.

      StringArray accepts array-likes containing nan-likes(`None`, `np.nan`) for the `values` parameter in addition to strings and `pandas.NA`

    dtype StringDtype

      Dtype for the array.

    copy bool, default False

      Whether to copy the array of data.

  Attributes

  None |

  Methods

  None |

  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")
      <ArrowStringArray>
      ['This is', 'some text', <NA>, 'data.']
      Length: 4, dtype: string

  Unlike arrays instantiated with `dtype="object"`, `StringArray` will convert the values to strings.

      >>> pd.array(["1", 1], dtype="object")
      <NumpyExtensionArray>
      ['1', 1]
      Length: 2, dtype: object
      >>> pd.array(["1", 1], dtype="string")
      <ArrowStringArray>
      ['1', '1']
      Length: 2, dtype: string

  However, instantiating StringArrays directly with non-strings will raise an error.

  For comparison methods, StringArray returns a `pandas.BooleanArray`:

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