栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Pandas中通过多处理读取csv文件的最简单方法

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Pandas中通过多处理读取csv文件的最简单方法

使用

Pool

import osimport pandas as pd from multiprocessing import Pool# wrap your csv importer in a function that can be mappeddef read_csv(filename):    'converts a filename to a pandas dataframe'    return pd.read_csv(filename)def main():    # get a list of file names    files = os.listdir('.')    file_list = [filename for filename in files if filename.split('.')[1]=='csv']    # set up your pool    with Pool(processes=8) as pool: # or whatever your hardware can support        # have your pool map the file names to dataframes        df_list = pool.map(read_csv, file_list)        # reduce the list of dataframes to a single dataframe        combined_df = pd.concat(df_list, ignore_index=True)if __name__ == '__main__':    main()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/639170.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号