Get last n records of a Pandas DataFrame Last Updated : 26 Jul, 2020 Comments Improve Suggest changes Like Article Like Report Let's discuss how to get last n records of a Pandas DAtaframe. There can be various methods to get the last n records of a Pandas DataFrame. Lets first make a dataframe:Example: Python3 # Import Required Libraries import pandas as pd import numpy as np # Create a dictionary for the dataframe dict = {'Name': ['Sukritin', 'Sumit Tyagi', 'Akriti Goel', 'Sanskriti', 'Abhishek Jain'], 'Age': [22, 20, np.inf, -np.inf, 22], 'Marks': [90, 84, 33, 87, 82]} # Converting Dictionary to Pandas Dataframe df = pd.DataFrame(dict) # Print Dataframe df Output:   Method 1: Using tail() method Use pandas.DataFrame.tail(n) to get the last n rows of the DataFrame. It takes one optional argument n (number of rows you want to get from the end). By default n = 5, it return the last 5 rows if the value of n is not passed to the method. Syntax: df.tail(n) Example: Python3 # Getting last 3 rows from df df_last_3 = df.tail(3) # Printing df_last_3 print(df_last_3) Output:   Method 2: Using pandas.DataFrame.iloc Use pandas.DataFrame.iloc to get last n rows. It is similar to the list slicing.Syntax: df.iloc[-n:] Example: Python3 # Getting last 3 rows from df df_last_3 = df.iloc[-3:] # Printing df_last_3 print(df_last_3) Output:  Method 3: Display last n records of specific columnsDisplay last n records for the specific column Python3 # Getting last 2 rows of columns # Age and Marks from df df_last_2 = df[['Age', 'Marks']].tail(2) # Printing df_last_2 print(df_last_2) Output:  Method 4: Display last n records from last n columnsDisplay last n records for the last n columns using pandas.DataFrame.iloc Python3 # Getting last n rows and last n columns from df df_last_2_row_col = df.iloc[-2:,-2:] # Printing df_last_2 print(df_last_2_row_col) Output: Comment More infoAdvertise with us Next Article Get last n records of a Pandas DataFrame S sukritinpal Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame pandas-dataframe-program Practice Tags : python Similar Reads Remove last n rows of a Pandas DataFrame Let's see the various methods to Remove last n rows of a Pandas Dataframe.First, let's make a dataframe: Python3 # Import Required Libraries import pandas as pd # Create a dictionary for the dataframe dict = { 'Name': ['Sukritin', 'Sumit Tyagi', 'Akriti Goel', 'Sanskriti', 'Abhishek Jain'], 'Age': [ 3 min read Get first N records in Pandas DataFrame When working with large datasets in Python using the Pandas library, it is often necessary to extract a specific number of records from a column to analyze or process the data, such as the first 10 values from a column. For instance, if you have a DataFrame df with column A, you can quickly get firs 5 min read How to get nth row in a Pandas DataFrame? Pandas Dataframes are basically table format data that comprises rows and columns. Now for accessing the rows from large datasets, we have different methods like iloc, loc and values in Pandas. The most commonly used method is iloc(). Let us consider a simple example.Method 1. Using iloc() to access 4 min read Get topmost N records within each group of a Pandas DataFrame Firstly, the pandas dataframe stores data in the form of a table. In some situations we need to retrieve data from dataframe according to some conditions. Such as if we want to get top N records of each group of the dataframe. We create the dataframe and use the methods mentioned below. Get topmost 2 min read Get Size of the Pandas DataFrame In this article, we will discuss how to get the size of the Pandas Dataframe using Python. Method 1 : Using df.size This will return the size of dataframe  i.e. rows*columns Syntax: dataframe.size where, dataframe is the input dataframe Example: Python code to create a student dataframe and display 2 min read Like