groupby optional setting (get_group or general?): getting a column value list per group instead of index
hello
When using the mighty groupby function, I found myself quite disappointed by something:
indeed, it is very useful regarding operations, but one of the most basic one is not mathematical.
It is about getting the values associated to a column (or series of columns) per group.

Maybe I missed something about the split-apply-combine strategy*, but I don't get how to retrieve simply the content of some rows for all or part of groups.
get_group() does this beautifully for one but not for many (i tried to pass sets, lists at no effect),
I can come up easily with something like:
groups_dict= {k: list(grouped.get_group(k).loc[:,idcolumn]) for k in grouped.groups.keys()}

But I guess this is not computationally efficient, plus it has to be repeated for all columns you want to aggregate.


Are there any better methods or wouldn't this be relevant to have a setting to output the actual values instead of an index?

I actually came up with another solution (agg_df being the original dataframe, you may need resetting the df index in case you used some exploding strategy):

groups_dict2= {k: list(agg_df2.loc[v,'n']) for k,v in grouped.indices.items()}

It feels slower but it is maybe more error proof?

Anyway, a function using all the hidden workings in Pandas would be far better I guess.

Best Regards

* (I am sorry, I try my best reading the docs, but Pandas is definitely not trivial to handle, docs are huge and when you think that you might find some problem's solution in one section or function domain, it can actually be something hugely different),

