# -*- coding:utf-8 -*-
import os
import time
import pandas as pd
from multiprocessing import Pool
def merge(filename):
return pd.read_csv('./fun_data/'+filename)
if __name__ == "__main__":
file_list = os.listdir('./fun_data')
e1 = time.time()
pool = Pool(20)
result = pool.map(merge,file_list)
pool.close()
pool.join()
e2 = time.time()
print(e2 - e1)
for i in result:
i.to_csv('./static.csv',mode='a',encoding='utf-8’,header=False,index=False)
e3 = time.time()
print(e3-e2)
比如:有很多的格式相同的pandas DF需要合并到同一个文件,可以利用这种方式。