Closed n49o7 closed 1 month ago
The example you have referenced isn't grouping based on the index of the series, but is using the list to do the grouping. It would have the same result as ser.groupby([0,1,0,1]).mean()
or ser.groupby([3,5,3,5]).mean()
Specifically from the docs:
If a list or ndarray of length equal to the selected axis is passed (see the groupby user guide), the values are used as-is to determine the groups.
thanks @asishm
maybe an extra sentence before each snippet could help, e.g.
We can pass a list of values to group by:
>>> ser.groupby(["a", "b", "a", "b"]).mean()
a 210.0
b 185.0
Name: Max Speed, dtype: float64
We can group by a level of the index:
>>> ser.groupby(level=0).mean()
Falcon 370.0
Parrot 25.0
Name: Max Speed, dtype: float64
We can pass a Series to group by:
>>> ser.groupby(ser > 100).mean()
Max Speed
False 25.0
True 370.0
would help make it clearer to users
Hi, I'd like to work on this issue. This would be my first time contributing to an open-source repository, and a well-renowned library like Pandas seems like a great place to start. Is this possible?
Thank you!
Yes, you don't need to ask for permission
take
Agree with that @MarcoGorelli I'd also change using a list with a/bs to something else to avoid the confusion that @n49o7 faced.
Hello,
On this page, in the first example, we can read
ser.groupby(["a", "b", "a", "b"]).mean()
.However,
a
andb
are not part of the index at this point. The index only hasFalcon
andParrot
: pandas/core/series.py L1818.Values
a
andb
are relevant for the third example: pandas/core/series.py L1862.