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?

2
  • Look if this is useful stackoverflow.com/questions/14674275/… Give me a feedback ;) Commented May 19, 2021 at 15:00
  • I think the correct parameter name is skiprows, not skiplines. Commented May 19, 2021 at 15:01

1 Answer 1

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.).

Sign up to request clarification or add additional context in comments.

1 Comment

It worked worderfully. Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.