Reading a Sample of Rows from a CSV

Python

To read a sample of rows from a csv into a Pandas Dataframe then use the nrows parameters to pass the number of rows required. This will import the first n rows of data from the csv where n is the value passed to the parameter.

In the example below we read the first 1000 rows from the csv into our dataframe.

 1|  import pandas as pd
 2|  
 3|  df = pd.read_csv('sales.csv', nrows=1000)
Did you find this snippet useful?

Sign up for free to to add this to your code library