Skipping Rows When Reading a CSV into a Pandas Dataframe


To skip rows when reading a csv into a Pandas dataframe, we can either pass a list of row indexes to skip into the skiprows parameter or we can pass an integer into the skiprows parameters which tells pandas how many rows to skip from the start of the csv.

In the below example we use both methods to skip the first 5 rows of the csv.

 1|  import pandas as pd
 3|  # skip the first 5 rows
 4|  df = pd.read_csv('sales.csv', skiprows=5)
 6|  # skip the rows indexed 0 to 4
 7|  rows_to_skip = [0, 1, 2, 3, 4]
 8|  df = pd.read_csv('sales.csv', skiprows=rows_to_skip)
Did you find this snippet useful?

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