@@ -77,77 +77,35 @@ API changes
77
77
78
78
- Using ``apply`` on resampling groupby operations (e.g. ``df.groupby(pd.TimeGrouper(freq='M', key='date')).apply(...)``) now has the same output types as similar ``apply``s on other groupby operations (e.g. ``df.groupby(pd.Grouper(key='color')).apply(...)``). (:issue:`11742`).
79
79
80
+
81
+ New Behavior:
82
+
83
+ .. ipython:: python
84
+
85
+ df = pd.DataFrame({'date': pd.to_datetime(['10/10/2000', '11/10/2000']), 'value': [10, 13]})
86
+ df
87
+ # Output is a Series
88
+ df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
89
+ # Output is a DataFrame
90
+ df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
91
+
80
92
Previous behavior:
81
93
82
94
.. code-block:: python
83
95
84
- In [1]: df = pd.DataFrame({'date': pd.to_datetime(['10/10/2000', '11/10/2000']), 'value': [10, 13]})
85
-
86
- In [2]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
87
- Out[2]:
96
+ In [1]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
97
+ Out[1]:
88
98
...
89
99
TypeError: cannot concatenate a non-NDFrame object
90
100
91
- In [3]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
92
- Out[3]:
101
+ # Output is a Series
102
+ In [2]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
103
+ Out[2]:
93
104
date
94
105
2000-10-31 value 10
95
106
2000-11-30 value 13
96
107
dtype: int64
97
108
98
- In [3]: type(df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum()))
99
- Out[3]: pandas.core.series.Series
100
-
101
-
102
- In [4]: df.groupby(pd.Grouper(key='date')).apply(lambda x: x.value.sum())
103
- Out[4]:
104
- date
105
- 2000-10-10 10
106
- 2000-11-10 13
107
- dtype: int64
108
-
109
- In [5]: type(df.groupby(pd.Grouper(key='date')).apply(lambda x: x.value.sum()))
110
- Out[5]: pandas.core.series.Series
111
-
112
-
113
- In [6]: df.groupby(pd.Grouper(key='date')).apply(lambda x: x[['value']].sum())
114
- Out[6]:
115
- value
116
- date
117
- 2000-10-10 10
118
- 2000-11-10 13
119
-
120
- In [7]: type(df.groupby(pd.Grouper(key='date')).apply(lambda x: x[['value']].sum()))
121
- Out[7]: pandas.core.frame.DataFrame
122
-
123
-
124
- New Behavior:
125
-
126
- .. code-block:: python
127
-
128
- In [1]: df = pd.DataFrame({'date': pd.to_datetime(['10/10/2000', '11/10/2000']), 'value': [10, 13]})
129
-
130
- In [2]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum())
131
- Out[2]:
132
- date
133
- 2000-10-31 10
134
- 2000-11-30 13
135
- Freq: M, dtype: int64
136
-
137
- In [3]: type(df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x.value.sum()))
138
- Out[3]: pandas.core.series.Series
139
-
140
-
141
- In [4]: df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum())
142
- Out[4]:
143
- value
144
- date
145
- 2000-10-31 10
146
- 2000-11-30 13
147
-
148
- In [5]: type(df.groupby(pd.TimeGrouper(key='date', freq='M')).apply(lambda x: x[['value']].sum()))
149
- Out[5]: pandas.core.frame.DataFrame
150
-
151
109
152
110
.. _whatsnew_0181.deprecations:
153
111
0 commit comments