Please convert below code to execute parallel, Here I'm trying to map nested dictionary with pandas column values. The below code works perfectly but consumes lot of time. Hence looking to parallelize the for loop(Note: df.replace(Source_Dictionary)
also did the job but takes triple the time of below code).
df = pd.DataFrame({'one':['bab'],'two':['abb'],'three':['bb']})
Source_Dictionary = {'one':{'dadd':1,'bab':1.5},
'two':{'ab':2},
'three':{'cc':1,'bb':3}}
required_columns = ['one','two','three']
def Feature_Map(x):
df[x] = df[x].map(Source_Dictionary[x]).fillna(0)
for i in required_columns:
Feature_Map(i)
print(df)
one two three
0 1.5 0.0 3
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…