Reading the subset of a file or a certain number of rows

Sometimes a data file is too big, and we just want to have a peek at the first few rows. We can do that by passing the number of rows to import to the nrows option, as shown in the following code. Here, we passed 100 to nrows, which then read only the first hundred rows from the dataset:

df = pd.read_csv('IMDB.csv', encoding = "ISO-8859-1", nrows=100)df.shape

Get Mastering Exploratory Analysis with pandas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.