Categories
Python Answers

How to skip rows during csv import with Python Pandas?

Spread the love

Sometimes, we want to skip rows during csv import with Python Pandas.

In this article, we’ll look at how to skip rows during csv import with Python Pandas.

How to skip rows during csv import with Python Pandas?

To skip rows during csv import with Python Pandas, we can call read_csv with the skiprows argument.

For instance, we write

import pandas as pd
from StringIO import StringIO

s = """1, 2
3, 4
5, 6"""

df = pd.read_csv(StringIO(s), skiprows=[1], header=None)

to call read_csv with the StringIO object with csv string s.

We set skiprows to [1] to skip the 2nd row.

And we set header to None to skip parsing the header.

Conclusion

To skip rows during csv import with Python Pandas, we can call read_csv with the skiprows argument.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *