Question:

A CSV file named customer.csv contains records of customers. The first row of the file represents the header. Sample data from the file is shown below:

Name, Age, City
Rudra,17,Kolkata
Divya,19,Dehradun
Nabeel,22,Lucknow

Write a Python program to import data from the CSV file into a Pandas DataFrame named DF and display the last two rows.

Show Hint

Read the file with pd.read_csv('customer.csv') into DF, then display the last two rows with DF.tail(2).
Updated On: Oct 20, 2026
Show Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Step 1: Understand the task:
The data sits in the file customer.csv, and its first row is a header. We must load it into a DataFrame called DF and show only the last two rows.

Step 2: Read the CSV file:
The Pandas function read_csv() reads a CSV file and returns a DataFrame.
By default it treats the first row as the header, which matches this file.
DF = pd.read_csv('customer.csv')


Step 3: Show the last two rows:
The method tail(n) returns the last n rows of a DataFrame. So DF.tail(2) gives the last two rows.

Step 4: Complete program:
import pandas as pd
DF = pd.read_csv('customer.csv')
print(DF.tail(2))


Step 5: Output for the sample data:
The code was run on the sample rows. It prints the last two customers.
     Name  Age      City
1   Divya   19  Dehradun
2  Nabeel   22   Lucknow

The row labels 1 and 2 come from the row numbers of the full table (0 is Rudra).

Final Answer:
Use DF = pd.read_csv('customer.csv') and then print(DF.tail(2)).
Was this answer helpful?
0
0