You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd love to be able to iterate over the groups in a Groupby. The only way that I know how to iterate over a Groupby currently is to use GroupBy#apply() — which is not documented, does not give the grouped value, and does not offer the same loop control as an iterable. I would prefer a more natural and readable approach for iteration (preferably a `for ... of`` loop).
Solution
I'd like the Groupby class to implement the iterable protocol with Symbol.iterator so that someone can use a for ... of loop (or even the spread syntax ...) to iterate over each group's value that it was grouped by and the data in that group as a DataFrame. This could be implemented similarly to how For example:
The documentation would also need to be updated to inform people that Groupby is iterable, preferably with an example of such.
Alternatives
You could also provide only each group's DataFrame (i.e. no value that it was grouped by), but that would be a bit annoying since I can't think of any situation where you'd want to group the data and then ignore the value that was used for grouping.
A complete alternative could be implementing a forEach method, but it would be quite odd to only implement the forEach method without implementing the iterable protocol given that implementing either of them is almost the same process while the iterable protocol gives greater control.
The text was updated successfully, but these errors were encountered:
What is the feature?
I'd love to be able to iterate over the groups in a
Groupby
. The only way that I know how to iterate over aGroupby
currently is to useGroupBy#apply()
— which is not documented, does not give the grouped value, and does not offer the same loop control as an iterable. I would prefer a more natural and readable approach for iteration (preferably a `for ... of`` loop).Solution
I'd like the
Groupby
class to implement the iterable protocol withSymbol.iterator
so that someone can use afor ... of
loop (or even the spread syntax...
) to iterate over each group's value that it was grouped by and the data in that group as aDataFrame
. This could be implemented similarly to how For example:The documentation would also need to be updated to inform people that
Groupby
is iterable, preferably with an example of such.Alternatives
You could also provide only each group's
DataFrame
(i.e. no value that it was grouped by), but that would be a bit annoying since I can't think of any situation where you'd want to group the data and then ignore the value that was used for grouping.A complete alternative could be implementing a
forEach
method, but it would be quite odd to only implement theforEach
method without implementing the iterable protocol given that implementing either of them is almost the same process while the iterable protocol gives greater control.The text was updated successfully, but these errors were encountered: