Instagram
youtube
Facebook
Twitter

Select the Last 5 Rows of a Pandas DataFrame

Select the Last 5 Rows of a Pandas DataFrame
     
Short Description of the Program:

 This program loads a CSV file into a Pandas DataFrame and uses the .tail() method to select the last 5 rows.
     
Explanation:

  • df.tail()
    This method returns the last 5 rows of the DataFrame by default.
    You can also use df.tail(3) to get the last 3 rows, for example.

Program:

import pandas as pd

df = pd.read_csv('data.csv')

last_five_rows = df.tail()

print(last_five_rows)