首页 > 编程 > Python > 正文

python分块读取大数据,避免内存不足的方法

2019-11-25 13:42:04
字体:
来源:转载
供稿:网友

如下所示:

def read_data(file_name): ''' file_name:文件地址 ''' inputfile = open(file_name, 'rb') #可打开含有中文的地址 data = pd.read_csv(inputfile, iterator=True) loop = True chunkSize = 1000 #一千行一块 chunks = [] while loop:  try:   chunk = dcs.get_chunk(chunkSize)   chunks.append(chunk)  except StopIteration:   loop = False   print("Iteration is stopped.") data = pd.concat(chunks, ignore_index=True) #print(train.head()) return data

以上这篇python分块读取大数据,避免内存不足的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表