I'm trying to take a dictionary and (1) raise each key to the power of its value, and (2) multiply together the results of (1).
This needs to be done to several million rows of data. Any thoughts on how to speed up the process? I am using pandas data frame's map function to apply the function toTheExp
to my column of data already. This step is still pretty slow though. Currently I'm trying something like:
import ast
from numpy import array
from functools import reduce
import operator
def toTheExp(d):
return reduce(operator.mul, array(d.keys())**array(d.values()), 1)
toTheExp({2:3,4:5,6:7})
>>> 2293235712