Python Pandas reads_csv跳过前x行和后y行 [英] Python Pandas reads_csv skip first x and last y rows

查看:95
本文介绍了Python Pandas reads_csv跳过前x行和后y行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我可能会在这里遗漏一些明显的东西,但是我是python和pandas的新手.我正在读取一个大文本文件,只想使用range(61,75496)中的行.我可以使用

I think I may be missing something obvious here, but I am new to python and pandas. I am reading a large text file and only want to use rows in range(61,75496). I can skip the first 60 rows with

keywords = pd.read_csv('keywords.list', sep='\t', skiprows=60)

如何仅在这些值之间包括行?不幸的是,没有 userows 参数.

How can I only include the rows inbetween these values? There unfortunately is no userows parameter.

是否存在

range(start, stop, start, stop)?

推荐答案

也许您可以使用nrows参数给出要读取的行数.

Maybe you can use the nrows argument to give the number of rows to read.

来自文档-

nrows : int, default None
Number of rows of file to read. Useful for reading pieces of large files

代码-

keywords = pd.read_csv('keywords.list', sep='\t', skiprows=60,nrows=75436) #Here 75436 is 75496 - 60

这篇关于Python Pandas reads_csv跳过前x行和后y行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆