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
DataFrame.tail(n=5)
Example
12345678910111213141516171819import 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))
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 3. Luku 3
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Suggested prompts:
Kysy minulta kysymyksiä tästä aiheesta
Tiivistä tämä luku
Näytä käytännön esimerkkejä
Awesome!
Completion rate improved to 2.7
The `tail()` Method
Pyyhkäise näyttääksesi valikon
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
DataFrame.tail(n=5)
Example
12345678910111213141516171819import 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))
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 3. Luku 3