In Python 3.11: to apply the square brackets operator to an object, the object's __getitem__
method should be implemented.
In Python's pandas
module it is possible to apply square brackets to objects returned from a DataFrame
by the groupby()
method, e.g. tips.groupby("sex")["total_bill"].count()
. (Example taken from this tutorial.)
However, there's no __getitem__
method listed in the pandas
' API reference for GroupBy
objects. How come? How is the square bracket operator implemented for pandas
GroupBy
objects?