@@ -43,15 +43,27 @@ fixed-width text files, and :func:`read_excel` for parsing Excel files.
43
43
pd.read_fwf(StringIO(data)).dtypes
44
44
pd.read_fwf(StringIO(data), dtype={'a':'float64', 'b':'object'}).dtypes
45
45
46
- You can now pass a dictionary mapping column names to desired data types for that
47
- column to :meth:`~DataFrame.astype`.
46
+ .. _whatsnew_0200.enhancements.groupby_access:
47
+
48
+ Groupby Enhancements
49
+ ^^^^^^^^^^^^^^^^^^^^
50
+
51
+ Strings passed to ``DataFrame.groupby()`` as the ``by`` parameter may now reference either column names or index level names (:issue:`5677`)
48
52
49
53
.. ipython:: python
50
54
51
- dft = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7, 8, 9]})
52
- dft = dft.astype({'a': np.float64, 'c': np.uint8})
53
- dft
54
- dft.dtypes
55
+ arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
56
+ ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
57
+
58
+ index = pd.MultiIndex.from_arrays(arrays, names=['first', 'second'])
59
+
60
+ df = pd.DataFrame({'A': [1, 1, 1, 1, 2, 2, 3, 3],
61
+ 'B': np.arange(8)},
62
+ index=index)
63
+ df
64
+
65
+ df.groupby(['second', 'A']).sum()
66
+
55
67
56
68
.. _whatsnew_0200.enhancements.other:
57
69
0 commit comments