Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

skip second row of dataframe while reading csv file in python

I am unable to skip the second row of a data file while reading a csv file in python.

I am using the following code :

imdb_data = pd.read_csv('IMDB_data.csv', encoding = "ISO-8859-1",skiprows = 2) 
like image 777
Sarang Kapse Avatar asked Aug 21 '18 13:08

Sarang Kapse


2 Answers

Your code will ommit the first two lines of your csv. If you want the second line to be ommitted (but the first one included) just do this minor change:

imdb_data = pd.read_csv('IMDB_data.csv', encoding = "ISO-8859-1",skiprows = [1]) 
like image 106
Matina G Avatar answered Sep 28 '22 07:09

Matina G


Looking at the documentation we can learn that if you supply an integer n for skiprows, the first n rows are skipped. If you want to skip single lines explicitly by line number (0 indexed), you must supply a list-like argument.

In your specific case, that would be skiprows=[1].

like image 40
timgeb Avatar answered Sep 28 '22 08:09

timgeb