How to skip rows during csv import with Python Pandas?

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.