What I want to do is iterate but keep the header from the first row. That’s just how indexing works in Python and pandas. Keep in mind that if we skip the first row, we must pass the names of the columns as further parameter. Read the first n rows in pandas. We usually want to skip the first line when the file is containing a header row, and we don’t want to print or import that row. Skipping CSV Rows. We can pass the skiprows parameter to skip rows from the CSV file. I am using below referred code to edit a csv using Python. You can, however, read only a few rows from the dataframe if you want to have a look at the data or do some simple analysis. import pandas emp_df = pandas.read_csv('employees.csv', skiprows=[2, 3]) print(emp_df) Output: Emp ID Emp Name Emp Role 0 1 Pankaj Kumar Admin 7. head (10)) Note that the last three rows have not been read. Note also that row with index 1 is the second row. Prerequisites: pandas. We can choose the starting row and how many rows we must load. 6. Also note that an additional parameter has been added which explicitly requests the use of the 'python… Row with index 2 is the third row and so on. Following are some different approaches to do the same: Data set in use: iris.csv dataset . You can use the pandas read_csv() function to read a CSV file. import pandas as pd df = pd.read_csv('hepatitis.csv', usecols=['age','sex']) Horizontal Filter. read_csv ('data_deposits.csv', sep = ',', skipfooter = 3, engine = 'python') print (df. The following is an example. import pandas as pd #skiprows=1 will skip first line and try to read from second line df = pd.read_csv('my_csv_file.csv', skiprows=1) ## pandas as pd #print the data frame df Solution 4: All of these answers miss one important point — the n’th line is the n’th line in the file, and not the n’th row … In this tutorial, we’ll look at how to read only the first n rows of a CSV file to a pandas dataframe. However, since the data you will usually use, have some sort of index themselves, let's say a 'timestamp' column, I would keep the index and load the data using it. Let’s say we want to skip the 3rd and 4th line from our original CSV file. import pandas as pd #skip three end rows df = pd. The row with index 3 is not included in the extract because that’s how the slicing syntax works. One way to use the CSV module and count row by row is with a for loop. One can open and edit CSV files in Python via Pandas library. Pandas : skip rows while reading csv file to a Dataframe using read_csv() in Python Python Pandas : Select Rows in DataFrame by conditions on multiple columns Pandas : Get frequency of a value in dataframe column/index & find its positions in Python Drop a row by row number (in this case, row 3) Note that Pandas uses zero based numbering, so 0 is the first row, 1 is the second row, etc. Method 1: Using slicing. As others have stated, if you don't want to save the index column in the first place, you can use df.to_csv('processed.csv', index=False). df . Python Pandas read_csv skip rows but keep header I'm having trouble figuring out how to skip n rows in a csv file but keep the header which is the 1 row. In this case we load only some rows of the dataset. While editing the file one might want to remove the entire row in the file. The readcsv method loads the data in a a Pandas dataframe that we named df. The data can be read using: from pandas import DataFrame, readcsv import matplotlib.pyplot as plt import pandas as pd file = r'highscore.csv' df = pd.readcsv(file) print(df) The first lines import the Pandas module. In this case, the loop iterates through a variable called line. In Python, while reading a CSV using the CSV module you can skip the first line using next() method. If you’re wondering, the first row of the dataframe has an index of 0. The for loop will iterate through lines in the CSV reader object previously assigned to this_csv_reader. drop ( df . index [ 2 ])