@@ -79,16 +79,51 @@ class Grouper:
7979 --------
8080 Syntactic sugar for ``df.groupby('A')``
8181
82- >>> df.groupby(Grouper(key='A'))
83-
84- Specify a resample operation on the column 'date'
85-
86- >>> df.groupby(Grouper(key='date', freq='60s'))
87-
88- Specify a resample operation on the level 'date' on the columns axis
89- with a frequency of 60s
90-
91- >>> df.groupby(Grouper(level='date', freq='60s', axis=1))
82+ >>> df = pd.DataFrame(
83+ ... {
84+ ... "Animal": ["Falcon", "Parrot", "Falcon", "Falcon", "Parrot"],
85+ ... "Speed": [100, 5, 200, 300, 15],
86+ ... }
87+ ... )
88+ >>> df
89+ Animal Speed
90+ 0 Falcon 100
91+ 1 Parrot 5
92+ 2 Falcon 200
93+ 3 Falcon 300
94+ 4 Parrot 15
95+ >>> df.groupby(pd.Grouper(key="Animal")).mean()
96+ Speed
97+ Animal
98+ Falcon 200
99+ Parrot 10
100+
101+ Specify a resample operation on the column 'Publish date'
102+
103+ >>> df = pd.DataFrame(
104+ ... {
105+ ... "Publish date": [
106+ ... pd.Timestamp("2000-01-02"),
107+ ... pd.Timestamp("2000-01-02"),
108+ ... pd.Timestamp("2000-01-09"),
109+ ... pd.Timestamp("2000-01-16")
110+ ... ],
111+ ... "ID": [0, 1, 2, 3],
112+ ... "Price": [10, 20, 30, 40]
113+ ... }
114+ ... )
115+ >>> df
116+ Publish date ID Price
117+ 0 2000-01-02 0 10
118+ 1 2000-01-02 1 20
119+ 2 2000-01-09 2 30
120+ 3 2000-01-16 3 40
121+ >>> df.groupby(pd.Grouper(key="Publish date", freq="1W")).mean()
122+ ID Price
123+ Publish date
124+ 2000-01-02 0.5 15.0
125+ 2000-01-09 2.0 30.0
126+ 2000-01-16 3.0 40.0
92127 """
93128
94129 _attributes : Tuple [str , ...] = ("key" , "level" , "freq" , "axis" , "sort" )
0 commit comments