Skip to content

Commit 991e54c

Browse files
DOC: Added examples in whatsnew
1 parent 3556126 commit 991e54c

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

doc/source/whatsnew/v1.0.0.rst

+31-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,37 @@ Deprecations
581581
it is recommended to use ``json_normalize`` as :func:`pandas.json_normalize` instead (:issue:`27586`).
582582
- :meth:`DataFrame.to_stata`, :meth:`DataFrame.to_feather`, and :meth:`DataFrame.to_parquet` argument "fname" is deprecated, use "path" instead (:issue:`23574`)
583583
- The deprecated internal attributes ``_start``, ``_stop`` and ``_step`` of :class:`RangeIndex` now raise a ``FutureWarning`` instead of a ``DeprecationWarning`` (:issue:`26581`)
584-
- When selecting columns from a :class:`DataFrameGroupBy` object, passing individual items in brackets is deprecated, should pass in a list of items instead. (:issue:`23566`)
584+
585+
**Selecting Columns from a Grouped DataFrame**
586+
587+
When selecting columns from a :class:`DataFrameGroupBy` object, passing individual keys (or a tuple of keys) inside single brackets is deprecated,
588+
a list of items should be used instead. (:issue:`23566`) For example:
589+
590+
.. code-block:: ipython
591+
592+
df = pd.DataFrame({
593+
"A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"],
594+
"B": np.random.randn(8),
595+
"C": np.random.randn(8),
596+
})
597+
g = df.groupby('A')
598+
599+
# single key, returns SeriesGroupBy
600+
g['B']
601+
602+
# tuple of single key, returns SeriesGroupBy
603+
g[('B',)]
604+
605+
# tuple of multiple keys, returns DataFrameGroupBy, raises FutureWarning
606+
g[('B','C')]
607+
608+
# multiple keys passed directly, returns DataFrameGroupBy, raises FutureWarning
609+
# (implicitly converts the passed strings into a single tuple)
610+
g['B','C']
611+
612+
# proper way, returns DataFrameGroupBy
613+
g[['B', 'C']]
614+
585615
586616
.. _whatsnew_1000.prior_deprecations:
587617

0 commit comments

Comments
 (0)