Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn The `tail()` Method | Fetching Data from DataFrames
Pandas: First Steps
course content

Course Content

Pandas: First Steps

Pandas: First Steps

1. Getting Started
2. Basics of Dataframes
3. Fetching Data from DataFrames

book
The `tail()` Method

The tail() method fetches the last few rows from a dataframe.

It also returns 5 rows by default. A custom number of rows can be specified using the n named parameter.

Syntax

js

Example

12345678910111213141516171819
import pandas as pd # Create a simple DataFrame about a bookstore books = pd.DataFrame({ 'Title': [ 'The Alchemist', '1984', 'To Kill a Mockingbird', 'The Great Gatsby', 'Moby Dick', 'Pride and Prejudice', 'War and Peace', 'The Hobbit', 'Crime and Punishment', 'Jane Eyre' ], 'Author': [ 'Paulo Coelho', 'George Orwell', 'Harper Lee', 'F. Scott Fitzgerald', 'Herman Melville', 'Jane Austen', 'Leo Tolstoy', 'J.R.R. Tolkien', 'Fyodor Dostoevsky', 'Charlotte BrontΓ«' ], 'Stock': [12, 8, 15, 7, 3, 10, 5, 9, 4, 6] }) print('Show the last 7 books in the list:') print(books.tail(n=3))
copy
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 3

Ask AI

expand
ChatGPT

Ask anything or try one of the suggested questions to begin our chat

course content

Course Content

Pandas: First Steps

Pandas: First Steps

1. Getting Started
2. Basics of Dataframes
3. Fetching Data from DataFrames

book
The `tail()` Method

The tail() method fetches the last few rows from a dataframe.

It also returns 5 rows by default. A custom number of rows can be specified using the n named parameter.

Syntax

js

Example

12345678910111213141516171819
import pandas as pd # Create a simple DataFrame about a bookstore books = pd.DataFrame({ 'Title': [ 'The Alchemist', '1984', 'To Kill a Mockingbird', 'The Great Gatsby', 'Moby Dick', 'Pride and Prejudice', 'War and Peace', 'The Hobbit', 'Crime and Punishment', 'Jane Eyre' ], 'Author': [ 'Paulo Coelho', 'George Orwell', 'Harper Lee', 'F. Scott Fitzgerald', 'Herman Melville', 'Jane Austen', 'Leo Tolstoy', 'J.R.R. Tolkien', 'Fyodor Dostoevsky', 'Charlotte BrontΓ«' ], 'Stock': [12, 8, 15, 7, 3, 10, 5, 9, 4, 6] }) print('Show the last 7 books in the list:') print(books.tail(n=3))
copy
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 3
We're sorry to hear that something went wrong. What happened?
some-alt