Skip to main content

__ Back to top

__ ` Ctrl ` \+ ` K `

[ ![pandas 2.2.1 documentation - Home](../_static/pandas.svg) ](../index.html)

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

  * [ 10 minutes to pandas ](10min.html)
  * [ Intro to data structures ](dsintro.html)
  * [ Essential basic functionality ](basics.html)
  * [ IO tools (text, CSV, HDF5, â¦) ](io.html)
  * [ PyArrow Functionality ](pyarrow.html)
  * [ Indexing and selecting data ](indexing.html)
  * [ MultiIndex / advanced indexing ](advanced.html)
  * [ Copy-on-Write (CoW) ](copy_on_write.html)
  * [ Merge, join, concatenate and compare ](merging.html)
  * [ Reshaping and pivot tables ](reshaping.html)
  * Working with text data 
  * [ Working with missing data ](missing_data.html)
  * [ Duplicate Labels ](duplicates.html)
  * [ Categorical data ](categorical.html)
  * [ Nullable integer data type ](integer_na.html)
  * [ Nullable Boolean data type ](boolean.html)
  * [ Chart visualization ](visualization.html)
  * [ Table Visualization ](style.html)
  * [ Group by: split-apply-combine ](groupby.html)
  * [ Windowing operations ](window.html)
  * [ Time series / date functionality ](timeseries.html)
  * [ Time deltas ](timedeltas.html)
  * [ Options and settings ](options.html)
  * [ Enhancing performance ](enhancingperf.html)
  * [ Scaling to large datasets ](scale.html)
  * [ Sparse data structures ](sparse.html)
  * [ Frequently Asked Questions (FAQ) ](gotchas.html)
  * [ Cookbook ](cookbook.html)

  * [ __ ](../index.html)
  * [ User Guide ](index.html)
  * Working... 

#  Working with text data  #

##  Text data types  #

There are two ways to store text data in pandas:

  1. ` object  ` -dtype NumPy array. 

  2. [ ` StringDtype  ` ](../reference/api/pandas.StringDtype.html#pandas.StringDtype "pandas.StringDtype") extension type. 

We recommend using [ ` StringDtype  `
](../reference/api/pandas.StringDtype.html#pandas.StringDtype
"pandas.StringDtype") to store text data.

Prior to pandas 1.0, ` object  ` dtype was the only option. This was
unfortunate for many reasons:

  1. You can accidentally store a _mixture_ of strings and non-strings in an ` object  ` dtype array. Itâs better to have a dedicated dtype. 

  2. ` object  ` dtype breaks dtype-specific operations like [ ` DataFrame.select_dtypes()  ` ](../reference/api/pandas.DataFrame.select_dtypes.html#pandas.DataFrame.select_dtypes "pandas.DataFrame.select_dtypes") . There isnât a clear way to select _just_ text while excluding non-text but still object-dtype columns. 

  3. When reading code, the contents of an ` object  ` dtype array is less clear than ` 'string'  ` . 

Currently, the performance of ` object  ` dtype arrays of strings and [ `
arrays.StringArray  `
](../reference/api/pandas.arrays.StringArray.html#pandas.arrays.StringArray
"pandas.arrays.StringArray") are about the same. We expect future enhancements
to significantly increase the performance and lower the memory overhead of [ `
StringArray  `
](../reference/api/pandas.arrays.StringArray.html#pandas.arrays.StringArray
"pandas.arrays.StringArray") .

Warning

` StringArray  ` is currently considered experimen