0

I have a csv file that contains 90000 lines with a date format index. I don't need to read the first 9 lines because that's info that doesn't concern me. I've tried like this:

df_dados = pd.read_csv('dados.csv', skiplines=9, index_col=0, parse_dates=['timestamp']) 

Unfortunally it doesn't work, and the only way I've surpassed this is by modifying the file which I wouldn't like to do. Is there a way to skip lines and set the time index?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
AmaFor
  • 13
  • 2

1 Answers1

0

The skiprows argument of pandas.read_csv() can be either list-like, an integer, or a callable.

  • List-like: Contains the line numbers to skip
  • Integer: Contains the line number to skip
  • Callable: Returns True or False depending on whether the row should be skipped or not.

Since you want to skip the first 9 lines, try passing skiprows=range(9).

df_dados = pd.read_csv('dados.csv', skiprows=range(9), index_col=0, parse_dates=['timestamp']) 

Note: The line numbers to skip are 0-indexed (first line is index 0, second is index 1, etc.).

Jacob Lee
  • 4,405
  • 2
  • 16
  • 37