我想在Python中进行多处理或并行处理。我写了下面的代码。
import pandas as pd
import multiprocessing
from joblib import Parallel, delayed
from tqdm import tqdm
num_cores = multiprocessing.cpu_count()
df = pd.DataFrame([["A",5],["B",4],["C",7]],columns=["item","val"])
inputs = ["A","B"]
def my_function(inputs):
for unique_id in inputs:
df3 code
df4 code
return (df3,df4)
if __name__ == "__main__":
df3,df4 = Parallel(n_jobs=num_cores)(delayed(my_function)(i) for i in inputs)```
I am able to get df3 and df4 output if save to csv file but while returning 2 variables I am getting following error:
***ValueError: not enough values to unpack (expected 2, got 1)***
What can be the possible reason? How to resolve it?
1条答案
按热度按时间tpgth1q71#
你的代码不清楚。但是,您可以尝试使用
zip
和pd.concat
: