How can I read first 500 records of excel file in Python?

python

#1

Hi,

I have 200 thousands records in an excel file but I want to import only first 500 records in the Python dataframe. Can you please help me to import only first 500 records?

Thx,
Imran


#2

@Imran,

You can use nrows option with read_csv command.

df = pd.read_csv("C:/Users/Analytics Vidhya/Desktop/temp.csv", nrows=5) 

Above statement will import only 5 records from CSV file.

You can also refer below URL for more option available with read_csv.

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.io.parsers.read_csv.html

Regards,
Sunil