您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

读取pandas数据框的前几行的方法

读取pandas数据框的前几行的方法

我认为您可以使用该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 pd

In [2]: time z = pd.read_csv("P00000001-ALL.csv", nrows=20)
cpu times: user 0.00 s, sys: 0.00 s, total: 0.00 s
Wall time: 0.00 s

In [3]: len(z)
Out[3]: 20

In [4]: time z = pd.read_csv("P00000001-ALL.csv")
cpu times: user 27.63 s, sys: 1.92 s, total: 29.55 s
Wall time: 30.23 s
其他 2022/1/1 18:25:02 有396人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶