python提取数据量大时用切片处理数据模板

## 1、sql
for chunk in pd.read_sql(sql,conn,chunksize=chunksize):
        count+=1
        df=chunk
        if count==1:
            save_sql(df,if_exists="replace")
            print("11",time.time()-time1)
            save_csv(df, mode='w')
        else:
            save_sql(df,if_exists="append")
            print("11",time.time()-time1)
            save_csv(df, mode='a')
        df=pd.DataFrame()
      
  ## 2、excel
  find=True
    while find==True:
        chunks=pd.read_excel(excelinputfilename,skiprows=skiprows,nrows=chunksize,header=0).values
        if len(chunks)>0:
            skiprows+=chunksize
            count+=1
            for chunk in chunks:
                word=chunk[0]

你可能感兴趣的:(python,python切片)