且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python Pandas read_csv跳过行,但保留头

更新时间:2023-01-29 19:14:58

p>您可以将行号列表传递给 skiprows ,而不是整数。然后读者将忽略列表中的那些行。

You can pass a list of row numbers to skiprows instead of an integer. The reader will then ignore those rows in the list.

通过给出函数的整数10,你只是跳过前10行。

By giving the function the integer 10, you're just skipping the first 10 lines.

要保留第一行0(作为标题),然后跳到第10行,您可以这样写:

To keep the first row 0 (as the header) and then skip to row 10, you could write:

pd.read_csv('test.csv', sep='|', skiprows=range(1, 10))