optimization - What is the trick behind the map function in Python? -
i have pandas data-frame , function of n arguments. now, each row utilize values n columns input function , output of function save in additional column. can in "direct" way:
inds = [] d = {} ind, row in df.iterrows(): inds.append(ind) d[ind] = my_func(row.col1, row.col2, row.col3) df['out_col'] = pandas.series(d, index = inds)
however, much more faster utilize following:
df['out_col'] = map(my_func, df.col1, df.col2, df.col3)
why much more faster "straightforward" solution. trick map function uses fast?
python optimization map pandas
No comments:
Post a Comment