网络编程
位置:首页>> 网络编程>> Python编程>> python分块读取大数据,避免内存不足的方法

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

作者:水木小僧  发布时间:2022-09-30 13:05:17 

标签:python,读取,大数据

如下所示:


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

来源:https://blog.csdn.net/Tony_Stark_Wang/article/details/81367837

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com