Table Of Contents
- What’s New
- Installation
- Contributing to pandas
- Package overview
- 10 Minutes to pandas
- Tutorials
- Cookbook
- Intro to Data Structures
- Essential Basic Functionality
- Working with Text Data
- Options and Settings
- Indexing and Selecting Data
- MultiIndex / Advanced Indexing
- Computational tools
- Working with missing data
- Group By: split-apply-combine
- Merge, join, and concatenate
- Reshaping and Pivot Tables
- Time Series / Date functionality
- Time Deltas
- Categorical Data
- Visualization
- Styling
- IO Tools (Text, CSV, HDF5, …)
- Enhancing Performance
- Sparse data structures
- Frequently Asked Questions (FAQ)
- rpy2 / R interface
- pandas Ecosystem
- Comparison with R / R libraries
- Comparison with SQL
- Comparison with SAS
- Comparison with Stata
- API Reference
- Input/Output
- General functions
- Series
- DataFrame
- Panel
- Index
- Numeric Index
- CategoricalIndex
- IntervalIndex
- MultiIndex
- DatetimeIndex
- TimedeltaIndex
- PeriodIndex
- Scalars
- Frequencies
- Window
- GroupBy
- Indexing, iteration
- Function application
- Computations / Descriptive Stats
- pandas.core.groupby.GroupBy.all
- pandas.core.groupby.GroupBy.any
- pandas.core.groupby.GroupBy.bfill
- pandas.core.groupby.GroupBy.count
- pandas.core.groupby.GroupBy.cumcount
- pandas.core.groupby.GroupBy.ffill
- pandas.core.groupby.GroupBy.first
- pandas.core.groupby.GroupBy.head
- pandas.core.groupby.GroupBy.last
- pandas.core.groupby.GroupBy.max
- pandas.core.groupby.GroupBy.mean
- pandas.core.groupby.GroupBy.median
- pandas.core.groupby.GroupBy.min
- pandas.core.groupby.GroupBy.ngroup
- pandas.core.groupby.GroupBy.nth
- pandas.core.groupby.GroupBy.ohlc
- pandas.core.groupby.GroupBy.prod
- pandas.core.groupby.GroupBy.rank
- pandas.core.groupby.GroupBy.pct_change
- pandas.core.groupby.GroupBy.size
- pandas.core.groupby.GroupBy.sem
- pandas.core.groupby.GroupBy.std
- pandas.core.groupby.GroupBy.sum
- pandas.core.groupby.GroupBy.var
- pandas.core.groupby.GroupBy.tail
- pandas.core.groupby.DataFrameGroupBy.agg
- pandas.core.groupby.DataFrameGroupBy.all
- pandas.core.groupby.DataFrameGroupBy.any
- pandas.core.groupby.DataFrameGroupBy.bfill
- pandas.core.groupby.DataFrameGroupBy.corr
- pandas.core.groupby.DataFrameGroupBy.count
- pandas.core.groupby.DataFrameGroupBy.cov
- pandas.core.groupby.DataFrameGroupBy.cummax
- pandas.core.groupby.DataFrameGroupBy.cummin
- pandas.core.groupby.DataFrameGroupBy.cumprod
- pandas.core.groupby.DataFrameGroupBy.cumsum
- pandas.core.groupby.DataFrameGroupBy.describe
- pandas.core.groupby.DataFrameGroupBy.diff
- pandas.core.groupby.DataFrameGroupBy.ffill
- pandas.core.groupby.DataFrameGroupBy.fillna
- pandas.core.groupby.DataFrameGroupBy.filter
- pandas.core.groupby.DataFrameGroupBy.hist
- pandas.core.groupby.DataFrameGroupBy.idxmax
- pandas.core.groupby.DataFrameGroupBy.idxmin
- pandas.core.groupby.DataFrameGroupBy.mad
- pandas.core.groupby.DataFrameGroupBy.pct_change
- pandas.core.groupby.DataFrameGroupBy.plot
- pandas.core.groupby.DataFrameGroupBy.quantile
- pandas.core.groupby.DataFrameGroupBy.rank
- pandas.core.groupby.DataFrameGroupBy.resample
- pandas.core.groupby.DataFrameGroupBy.shift
- pandas.core.groupby.DataFrameGroupBy.size
- pandas.core.groupby.DataFrameGroupBy.skew
- pandas.core.groupby.DataFrameGroupBy.take
- pandas.core.groupby.DataFrameGroupBy.tshift
- pandas.core.groupby.SeriesGroupBy.nlargest
- pandas.core.groupby.SeriesGroupBy.nsmallest
- pandas.core.groupby.SeriesGroupBy.nunique
- pandas.core.groupby.SeriesGroupBy.unique
- pandas.core.groupby.SeriesGroupBy.value_counts
- pandas.core.groupby.SeriesGroupBy.is_monotonic_increasing
- pandas.core.groupby.SeriesGroupBy.is_monotonic_decreasing
- pandas.core.groupby.DataFrameGroupBy.corrwith
- pandas.core.groupby.DataFrameGroupBy.boxplot
- Resampling
- Style
- Plotting
- General utility functions
- Extensions
- Developer
- Internals
- Extending Pandas
- Release Notes
Search
Enter search terms or a module, class or function name.
pandas.core.groupby.GroupBy.tail¶
-
GroupBy.
tail
(n=5)[source]¶ Returns last n rows of each group
Essentially equivalent to
.apply(lambda x: x.tail(n))
, except ignores as_index flag.Examples
>>> df = DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]], columns=['A', 'B']) >>> df.groupby('A').tail(1) A B 1 a 2 3 b 2 >>> df.groupby('A').head(1) A B 0 a 1 2 b 1