Skip to content

Commit f4cd63d

Browse files
DOC: update whatsnew section for pd.col() (#63380)
1 parent 0b156d6 commit f4cd63d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,18 @@ and will be removed in pandas 4.0.
131131

132132
.. _whatsnew_300.enhancements.col:
133133

134-
``pd.col`` syntax can now be used in :meth:`DataFrame.assign` and :meth:`DataFrame.loc`
135-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134+
Initial support for ``pd.col()`` syntax to create expressions
135+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
136136

137-
You can now use ``pd.col`` to create callables for use in dataframe methods which accept them. For example, if you have a dataframe
137+
This release introduces :func:`col` to refer to a DataFrame column by name
138+
and build up expressions.
139+
140+
This can be used as a simplified syntax to create callables for use in
141+
methods such as :meth:`DataFrame.assign`. In practice, where you would
142+
have to use a ``lambda`` function before, you can now use ``pd.col()``
143+
instead.
144+
145+
For example, if you have a dataframe
138146

139147
.. ipython:: python
140148
@@ -152,6 +160,18 @@ you can now write:
152160
153161
df.assign(c = pd.col('a') + pd.col('b'))
154162
163+
The expression object returned by :func:`col` supports all standard operators
164+
(like ``+``, ``-``, ``*``, ``/``, etc.) and all Series methods and namespaces
165+
(like ``pd.col("name").sum()``, ``pd.col("name").str.upper()``, etc.).
166+
167+
Currently, the ``pd.col()`` syntax can be used in any place which accepts a
168+
callable that takes the calling DataFrame as first argument and returns a
169+
Series, like ``lambda df: df[col_name]``.
170+
This includes :meth:`DataFrame.assign`, :meth:`DataFrame.loc`, and getitem/setitem.
171+
172+
It is expected that the support for ``pd.col()`` will be expanded to more methods
173+
in future releases.
174+
155175
New Deprecation Policy
156176
^^^^^^^^^^^^^^^^^^^^^^
157177
pandas 3.0.0 introduces a new 3-stage deprecation policy: using ``DeprecationWarning`` initially, then switching to ``FutureWarning`` for broader visibility in the last minor version before the next major release, and then removal of the deprecated functionality in the major release. This was done to give downstream packages more time to adjust to pandas deprecations, which should reduce the amount of warnings that a user gets from code that isn't theirs. See `PDEP 17 <https://pandas.pydata.org/pdeps/0017-backwards-compatibility-and-deprecation-policy.html>`_ for more details.

pandas/core/col.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ def col(col_name: Hashable) -> Expression:
260260
:meth:`DataFrame.assign` or :meth:`DataFrame.loc`, can also accept
261261
``pd.col(col_name)``.
262262
263+
.. versionadded:: 3.0.0
264+
263265
Parameters
264266
----------
265267
col_name : Hashable

0 commit comments

Comments
 (0)