当前位置:主页 > 软件编程 > Python代码 >

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

时间:2021-04-02 09:46:37 | 栏目: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

您可能感兴趣的文章:

相关文章