Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.arrays.StringArray#

classpandas.arrays.StringArray(values,copy=False)[source]#

Extension array for string data.

Warning

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

Parameters:
valuesarray-like

The array of data.

Warning

Currently, this expects an object-dtype ndarraywhere the elements are Python stringsor nan-likes (None,np.nan,NA).This may change without warning in the future. Usepandas.array() withdtype="string" for a stable way ofcreating aStringArray from any sequence.

Changed in version 1.5.0:StringArray now accepts array-likes containingnan-likes(None,np.nan) for thevalues parameterin addition to strings andpandas.NA

copybool, default False

Whether to copy the array of data.

Attributes

None

Methods

None

See also

pandas.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 arrays instantiated withdtype="object",StringArraywill convert the values to strings.

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

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

For comparison methods,StringArray returns apandas.BooleanArray:

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

[8]ページ先頭

©2009-2025 Movatter.jp