diff --git a/doc/source/cookbook.rst b/doc/source/cookbook.rst index edff461d7989d..8378873db9a65 100644 --- a/doc/source/cookbook.rst +++ b/doc/source/cookbook.rst @@ -588,6 +588,19 @@ Unlike agg, apply's callable is passed a sub-DataFrame which gives you access to df['beyer_shifted'] = df.groupby(level=0)['beyer'].shift(1) df +`Select row with maximum value from each group +`__ + +.. ipython:: python + + df = pd.DataFrame({'host':['other','other','that','this','this'], + 'service':['mail','web','mail','mail','web'], + 'no':[1, 2, 1, 2, 1]}).set_index(['host', 'service']) + mask = df.groupby(level=0).agg('idxmax') + df_count = df.loc[mask['no']].reset_index() + df_count + + Expanding Data ************** @@ -1202,4 +1215,4 @@ of the data values: {'height': [60, 70], 'weight': [100, 140, 180], 'sex': ['Male', 'Female']}) - df \ No newline at end of file + df