我认为您可以使用该
nrows参数。从文档:
nrows : int, default None Number of rows of file to read. Useful for reading pieces of large files
这似乎有效。使用标准大型测试文件之一(988504479字节,5344499行):
In [1]: import pandas as pdIn [2]: time z = pd.read_csv("P00000001-ALL.csv", nrows=20)CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 sWall time: 0.00 sIn [3]: len(z)Out[3]: 20In [4]: time z = pd.read_csv("P00000001-ALL.csv")CPU times: user 27.63 s, sys: 1.92 s, total: 29.55 sWall time: 30.23 s


