Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 07125ea

Browse files
DOC: add select_dtypes case to 3.0 string migration guide (#62403)
1 parent 831d29d commit 07125ea

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎doc/source/user_guide/migration-3-strings.rst‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ This is actually compatible with pandas 2.x as well, since in pandas < 3,
195195
of also stringifying missing values in pandas 2.x. See the section
196196
:ref:`string_migration_guide-astype_str` for more details.
197197

198+
For selecting string columns with :meth:`~DataFrame.select_dtypes` in a pandas
199+
2.x and 3.x compatible way, it is not possible to use ``"str"``. While this
200+
works for pandas 3.x, it raises an error in pandas 2.x.
201+
As an alternative, you can select both ``object`` (for pandas 2.x) and
202+
``"string"`` (for pandas 3.x; which will also select the default ``str`` dtype
203+
and does not error on pandas 2.x):
204+
205+
.. code-block:: python
206+
207+
# can use ``include=["str"]`` for pandas >= 3
208+
>>> df.select_dtypes(include=["object", "string"])
209+
198210
199211
The missing value sentinel is now always NaN
200212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /