Use the tail() method to print the last n rows of a DataFrame.
Optional Parameters
- n
- Specifies the number of rows to select.
Default value: 10
- deterministic
- Specifies whether to select the last n rows from the sorted DataFrame or not.
- If True, the last n rows of the sorted DataFrame are selected.
The DataFrame is sorted on the index column or the first column if there is no index column. The column type must support sorting.
Unsupported types include: 'BLOB', 'CLOB', 'ARRAY', 'VARRAY'.
- If False, a random sample of n rows is selected.
Default value: True.
- If True, the last n rows of the sorted DataFrame are selected.
Example 1: Print default number of rows
The following example prints the default last 10 rows of "admissions_train" sorted by id.
>>>df.tail() masters gpa stats programming admitted id 38 yes 2.65 advanced beginner 1 36 no 3.00 advanced novice 0 35 no 3.68 novice beginner 1 34 yes 3.85 advanced beginner 0 32 yes 3.46 advanced beginner 0 31 yes 3.50 advanced beginner 1 33 no 3.55 novice novice 1 37 no 3.52 novice novice 1 39 yes 3.75 advanced beginner 0 40 yes 3.95 novice beginner 0
Example 2: Print n rows
The following example prints the last 3 rows of "admissions_train":
>>>df.tail(3) masters gpa stats programming admitted id 38 yes 2.65 advanced beginner 1 39 yes 3.75 advanced beginner 0 40 yes 3.95 novice beginner 0
The following example prints the last 15 rows of "admissions_train":
>>>df.tail(15) masters gpa stats programming admitted id 38 yes 2.65 advanced beginner 1 36 no 3.00 advanced novice 0 35 no 3.68 novice beginner 1 34 yes 3.85 advanced beginner 0 32 yes 3.46 advanced beginner 0 31 yes 3.50 advanced beginner 1 30 yes 3.79 advanced novice 0 29 yes 4.00 novice beginner 0 28 no 3.93 advanced advanced 1 27 yes 3.96 advanced advanced 0 26 yes 3.57 advanced advanced 1 33 no 3.55 novice novice 1 37 no 3.52 novice novice 1 39 yes 3.75 advanced beginner 0 40 yes 3.95 novice beginner 0
Example 3: Print 3 rows of "admissions_train" with deterministic argument set to False
>>> df.tail(3, deterministic=False)
masters gpa stats programming admitted
id
33 no 3.55 Novice Novice 1
37 no 3.52 Novice Novice 1
20 yes 3.90 Advanced Advanced 1