小编Sud*_*ari的帖子

how to write content of df into csv file using multiprocessing in python

I have a function that writes the content of df into csv file.

def writeToCSV(outDf, defFile, toFile, retainFlag=True, delim='\t', quotechar='"'):
    headers = []
    fid = open(defFile, 'r')
    for line in fid:
        headers.append(line.replace('\r','').split('\n')[0].split('\t')[0])
    df = pd.DataFrame([], columns=headers)
    for header in outDf.columns.values:
        if header in headers:
            df[header] = outDf[header]

    df.to_csv(toFile, sep=delim, quotechar=quotechar, index=False, encoding='utf-8')
Run Code Online (Sandbox Code Playgroud)

How can i parallelize this process? Currently i am using following code

def writeToSchemaParallel(outDf, defFile, toFile, retainFlag=True, delim='\t', quotechar='"'):
    logInfo('Start writingtoSchema in parallel...', 'track')
    headers = []
    fid …
Run Code Online (Sandbox Code Playgroud)

python csv multiprocessing dataframe pandas

1
推荐指数
1
解决办法
3734
查看次数

标签 统计

csv ×1

dataframe ×1

multiprocessing ×1

pandas ×1

python ×1