python如何读取csv文件某几行某几列_使用python只读取csv文件中的某些行

正如其他人所说,最明显的解决方案是使用熊猫读csv!

该方法有一个名为skiprows的参数:

skiprows:list-like,int或callable,可选

文件开始时要跳过的行号(0索引)或要跳过的行数(int)。在

如果可调用,将根据行索引计算可调用函数,如果应跳过该行,则返回True;否则返回False。一个有效的可调用参数的例子是[0,2]中的lambda x:x。

你可以这样做:import pandas as pd

data = pd.read_csv('path/to/your/file', skiprows =lambda x: x not in range(50, 60))

由于您指定内存是您的问题,因此可以使用this tutorial中所述的chunksize参数

他说:The parameter essentially means the number of rows to be read into a

dataframe at any single time in order to fit into the local memory.

Since the data consists of more than 70 millions of rows, I specified

the chunksize as 1 million rows each time that broke the large data

set into many smaller pieces.

^{pr2}$

您可以尝试这样做,然后在块上迭代,只检索要查找的行。在

如果行号在指定列表中,则函数应返回true

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值